mongodb-query

Insert the $currentDate on mongodb with pymongo

情到浓时终转凉″ 提交于 2019-12-24 10:30:56
问题 I need test the accuracy of a server mongodb. I am trying to insert a sequence of data, take the moment and it was sent to the database to know when it was inserted. I'm trying this: #!/usr/bin/python from pymongo import Connection from datetime import date, timedelta, datetime class FilterData: @classmethod def setData(self, serialData): try: con = Connection('IP_REMOTE', 27017, safe=True) db = con['resposta'] inoshare = db.resposta inoshare.insert(serialData) con.close() except Exception as

SyntaxError: invalid property id - MongoDB

僤鯓⒐⒋嵵緔 提交于 2019-12-24 10:24:26
问题 I am from an Oracle PLSQL background and I have just started learning MongoDB commands. >db.Employee.find() { "_id" : 10, "EmployeeName" : "Smith" } { "_id" : 20, "EmployeeName" : "Nandhi" } { "_id" : 30, "EmployeeName" : "Rajan" } { "_id" : 50, "EmployeeName" : "Raju" } I need to query the documents like: WHERE EmployeeName = "Smith" OR (EmployeeName = "Rajan" AND _id = 30); I have written the corresponding code as below: db.Employee.find({$or:[{"EmployeeName":"Smith",{"EmployeeName":"Rajan"

TypeError: callback.apply is not a function after allowDiskUse

点点圈 提交于 2019-12-24 09:08:04
问题 I have a collection having 1Million documents... I have passed the option for allowDiskUse and now it is throwing error TypeError: callback.apply is not a function I have searched for this but could get the solution... Please help const pictures = await Picture.aggregate([ { $sort: { createdAt: -1 }}, { $group: { _id: { $dateToString: { format: "%Y-%m-%d", date: "$createdAt" } }, pictures: { $push: { _id: '$_id', image: '$image', time: { $dateToString: { format: "%H:%M:%S", date: "$createdAt"

Using a Dynamic Value in Aggregation

て烟熏妆下的殇ゞ 提交于 2019-12-24 08:52:35
问题 I have a document structure like this: { "_id" : ObjectId("59d7cd63dc2c91e740afcdb"), "dateJoined": ISODate("2014-12-28T16:37:17.984Z"), "dateActivated": ISODate("2015-02-28T16:37:17.984Z"), "enrolled" : [ { "month":-10, "enrolled":'00'}, { "month":-9, "enrolled":'00'}, { "month":-8, "enrolled":'01'}, //other months { "month":8, "enrolled":'11'}, { "month":9, "enrolled":'11'}, { "month":10, "enrolled":'00'} ] } "month" value in enrolled is relative to dateJoined that range from -X to +X that

mongoDB updateOne not updating a record

有些话、适合烂在心里 提交于 2019-12-24 08:40:24
问题 I am trying to update a record in mongoDB using updateOne, the un updating record is in array, and all fields are updating except one field which is country , I have tried to update it using MongoChef (a GUI of MongoDB for linux), but it doesn't work, also If I update one the Document using Edit in GUI then that record is ready to update after that . I have tried with the following query in MongoChef db.institutions.updateOne({ "campus": { "$elemMatch": { "_id": ObjectId(

How select data with given condition

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 08:12:25
问题 I have following data. { "name" : "Maria", "facebook" : [ { "data" : "fb.com", "privacy" : true } ], "twitter" : [ { "data" : "twitter.com", "privacy" : false } ], "google" : [ { "data" : "google.com", "privacy" : true } ], "phno" : [ { "data" : "+1-1289741824124", "privacy" : true } ] } I want to return only data having privacy is equal to true. How do I do it ? I tried but it returns all data having privacy is equal to false also. How do I query the data ? Please post MongoDB query not

remove “\n” from values fields results in mongo db

99封情书 提交于 2019-12-24 08:09:36
问题 How can I remove "\n" from results of searching values in mongo db without remove it from the values of mongo db ? please I need your help! 回答1: Example with 2 documents: db.testcol.insert({ textstr: "Hello World\nBye World\nHello World\n" }) db.testcol.insert({ textstr: "Testing\n123\nTesting\n" }) db.testcol.find({}, {_id: 0, textstr: 1}).forEach(function(e, i) { e.textstr=e.textstr.replace(new RegExp('\n', 'g'), ""); printjson(e); }); Will output: { "textstr" : "Hello WorldBye WorldHello

How to project specific fields in array on filtered lookup

丶灬走出姿态 提交于 2019-12-24 08:06:16
问题 I am combining two collection using $lookup and I am able to apply a filter on the 'joined' collection and use a projection on the starting collection , but I did not manage to combine both a filter and a projection on the joined collection trying several approach using $redact and $project. I have looked intensively on stackoverflow, but I could not find this combination. Here come an example: collection meta: { "Exp": "A","test": "OK","date": "3"} { "Exp": "B","test": "OK","date": "5"} {

Upsert mongo array of object with condition

风格不统一 提交于 2019-12-24 07:45:18
问题 I have a collection with some documents and each document has ha list of objects representing a temporal interval in epoch with a keyword. I want to update the final value of the interval of each object in the right document where the ending value is greater than a value. If nothing can be updated I want to insert a new interval with both start and end as the new value and with the keyword used in the query. I'm using nifi to perform this task and the update block, with upsert enabled. I can

Upsert mongo array of object with condition

喜夏-厌秋 提交于 2019-12-24 07:42:04
问题 I have a collection with some documents and each document has ha list of objects representing a temporal interval in epoch with a keyword. I want to update the final value of the interval of each object in the right document where the ending value is greater than a value. If nothing can be updated I want to insert a new interval with both start and end as the new value and with the keyword used in the query. I'm using nifi to perform this task and the update block, with upsert enabled. I can