mongodb-query

MongoDB - Error: getMore command failed: Cursor not found

自作多情 提交于 2019-12-27 14:42:55
问题 I need to create a new field sid on each document in a collection of about 500K documents. Each sid is unique and based on that record's existing roundedDate and stream fields. I'm doing so with the following code: var cursor = db.getCollection('snapshots').find(); var iterated = 0; var updated = 0; while (cursor.hasNext()) { var doc = cursor.next(); if (doc.stream && doc.roundedDate && !doc.sid) { db.getCollection('snapshots').update({ "_id": doc['_id'] }, { $set: { sid: doc.stream.valueOf()

MongoDB - Error: getMore command failed: Cursor not found

只愿长相守 提交于 2019-12-27 14:42:13
问题 I need to create a new field sid on each document in a collection of about 500K documents. Each sid is unique and based on that record's existing roundedDate and stream fields. I'm doing so with the following code: var cursor = db.getCollection('snapshots').find(); var iterated = 0; var updated = 0; while (cursor.hasNext()) { var doc = cursor.next(); if (doc.stream && doc.roundedDate && !doc.sid) { db.getCollection('snapshots').update({ "_id": doc['_id'] }, { $set: { sid: doc.stream.valueOf()

Get a count of total documents with MongoDB when using limit

99封情书 提交于 2019-12-27 11:04:58
问题 I am interested in optimizing a "pagination" solution I'm working on with MongoDB. My problem is straight forward. I usually limit the number of documents returned using the limit() functionality. This forces me to issue a redundant query without the limit() function in order for me to also capture the total number of documents in the query so I can pass to that to the client letting them know they'll have to issue an additional request(s) to retrieve the rest of the documents. Is there a way

Mongodb Aggregation command to java code

走远了吗. 提交于 2019-12-25 18:35:44
问题 Convert shell command to Java code, Hi what iam trying to do is, GROUP collection by "sourceSystemName" and get values of logID,type,_id,sourceSystemName,logTime for MAX "logTime" Collection Sample Data:(contains 1million data) { "logID" : "1487408645950", "logTime" : ISODate("2017-02-6T06:47:59Z"), "type" : "SYSTEM_MONITOR", "sourceSystemId" :"192.168.1.226", "sourceSystemName" : "LOADER.LOG" } { "logID" : "1488226732268", "logTime" : ISODate("2017-02-16T06:48:00Z"),"type" : "SYSTEM_MONITOR"

Mongodb Search nested array elements

爱⌒轻易说出口 提交于 2019-12-25 09:42:38
问题 I have a below data. Would like to search aclpermissions where any of the elements (CRT, READ, DLT, UPD) will match to an array of inputs. Below query db.AMSAppACL.find({"aclpermissions.READ" : {'$in': ['58dc0bea0cd182789fc62fab']}}).pretty(); only searches READ element. Is there any way to search all the elements instead of using or queries and aggregate { "_id" : ObjectId("5900d6abb9eb284a78f5a350"), "_class" : "com.debopam.amsapp.model.AMSAppACL", "attrUniqueCode" : "USER",

Find based on calculated difference

安稳与你 提交于 2019-12-25 09:29:08
问题 I need to query my Mongo DB based on some parameters. However, to get the parameter, I first need to use a find() anyway and then do some calculations. This, obviously, is not efficient. Let me elaborate: Here is my collection I want to query: { "title": "1", "description": "1", "aCounter": 100, "bCounter": 20, "__v": 0 } I want to find posts where aCounter - bCounter is more than 50 . I have the model and everything ready but don't know about what to put in the find() parameters. postModel

MongoDb aggregation $lookup with foreign _ids in arrays

自古美人都是妖i 提交于 2019-12-25 09:27:10
问题 I'm a MongoDb novice. I'm getting pretty good, but no expert yet. I'm trying setup my collections in a way that makes sense. I'd like to keep some links to foreign docs inside arrays of just _ids and also arrays of objects that have _ids. I created a JSON doc with notes that I think fully shows what I'm trying to do... // ( item ) Character Inventory/Items collection [ { "_id": "1234", "name": "Sword", "descr": "Long sword, well worn, light rust", "encumber": 2, "del": false }, { "_id": "1271

Mongodb can't find object with too long _id

老子叫甜甜 提交于 2019-12-25 09:04:53
问题 I have a little bit strange situation. I persist objects in collection "refs" explicitly setting _id. So I have objects with very big id's. db.refs.find().sort({_id: -1}); // {_id: 9200000000165761625} // ... But when I try to find object with biggest id in mongo shell it returns nothing: db.refs.find({_id: 9200000000165761625}); // nothing But! db.refs.find({_id: 9200000000165761625}).count(); // return 1 How could this happen? 回答1: i could not reproduce your problem. i was able to

Solr Delta Import Query is not working

倖福魔咒の 提交于 2019-12-25 08:04:09
问题 I am trying to import data from Mongodb to Solr6.0. Full import is executing properly but delta import is not working. When I execute delta import I get below result. Requests: 0 , Fetched: 0 , Skipped: 0 , Processed: 0 My data config file queries are as below query="" deltaQuery="db.getCollection('customer').find({'jDate':{$gt:'${dih.last_index_time}'}},{'_id' :1});" deltaImportQuery="db.getCollection('customer').find({'_id':'${dataimporter.delta.id}'})" the whole data-config.xml <?xml

Finding records whose object contains a String value

强颜欢笑 提交于 2019-12-25 08:01:14
问题 I have a collection, the document in it looks like this: { "person-name" : "Hughart, Ron", "info" : { "birthnotes" : [ "Los Angeles, California, USA" ], "birthdate" : [ "18 June 1961" ], "birthname" : [ "Hughart, Ronald P" ] } } I want to find the people who were born in Lisbon. The question is how do I know if a record's field "info.birthnotes" contains "Lisbon" ? I tried this command: db.collection.find({"info.birthnotes": {"$in": ["Lisbon"]}}) but it returns nothing. 回答1: From inspection,