In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Connect to the mongodb:
Public class GenericMga {private DB db; public DB getDB () {return this.db;} public void setDB (DB db) {this.db = db;}} DBCollection coll= null;coll=getDB (). GetCollection ("collName"); / / the save name is equivalent to the table name of MySQL
Create query criteria:
BasicDBObject query = new BasicDBObject (); query.append ("type", type); / / "type" queries all data that meets the type=type criteria for the fields in the table / / queries the data query.append ("time", new BasicDBObject ("$gte", searchStartTime) .append ("$lte", searchEndTime)) between time and the fields in the table ("time", new BasicDBObject ("$gte", searchStartTime) .append ("$lte", searchEndTime); query.append ("role", "{$exists:true}"); / / queries the data DBCursor cursor = coll.find (query) that exists in the role field While (cursor.hasNext ()) {cursor.next ();}
If you only want to query a field or fields, you can create a query as another query condition:
BasicDBObject query1 = new BasicDBObject (); query1.append ("user", 1); / / means only user is queried (default _ id also exists. If you don't want it, you can set it as follows) query1.append ("_ id", 0); / / does not show the _ id field DBCursor cursor = coll.find (query,query1); while (cursor.hasNext ()) {cursor.next ();}
Query the document: db.DeviceInfo.find that exists in the role field ({"role": {$exists: true}})
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.