Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Query using conditional operators in [mongoDB] Java

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Operators such as $in are often used when querying, such as db.collection_0.find ("_ id": {"$in", "0001", "0002", "0003"}).

But how shell should be written in shell,java, take $in as an example here.

PS: I like $in, especially when key is an array type.

I use mongo-java-driver 2.11.0

Now I have a collection named col_0, and I save something like this in it.

Suppose this is a user with an id of 0001 who has 0002 and 0003 friends.

Now I want to query the friends of a user's friends, such as "recommend friends".

For Java code, you can probably write something like this:

DB db = MonFactory.getInstance (). GetMongo (). GetDB ("test"); DBCollection dbCollection = db.getCollection ("col_0"); BasicDBObject term = new BasicDBObject (); term.put ("_ id", uid); DBObject curUserData = dbCollection.findOne (term); List p4pList = new ArrayList (); p4pList.addAll ((Collection)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report