mongodb-query

is It possible to compare two Months Data in single Collection in MongoDB?

房东的猫 提交于 2021-02-08 11:58:17
问题 I have collection database with 10 000 000 call records. I want to compare call usage of previous month to next month. Example of collection document { "_id" : ObjectId("54ed74d76c68d23af73e230a"), "msisdn" : "9818441000", "callType" : "ISD" "duration" : 10.109999656677246, "charges" : 200, "traffic" : "Voice", "Date" : ISODate("2014-01-05T19:51:01.928Z") } { "_id" : ObjectId("54ed74d76c68d23af73e230b"), "msisdn" : "9818843796", "callType" : "Local", "duration" : 1, "charges" : 150, "traffic"

MongoDB $lookup on one document's array of object

感情迁移 提交于 2021-02-08 03:31:18
问题 I have searched online but could not find any match my case. Here is the situation. I am using aggregate to combine one collection and one document which is from another collection together restaurants.aggregate([ { $match: { _id: { $in: idList } } }, { $lookup: { from: "tags", localField: "details.restaurantType", foreignField: "details.restaurantType._id", as: "types" } }, { $project: { restaurantName: "$details.restaurantName", restaurantType: "$details.restaurantType", type: { $filter: {

Getting Distinct values of multiple values in Mongodb

。_饼干妹妹 提交于 2021-02-07 18:17:00
问题 Let's imagine I have the following collection of books (Edited out the ID field for compactness): { "author" : "Steve Jones", "title" : "Fun Stuff", "edition" : "2010" } { "author" : "Steve Jones", "title" : "Fun Stuff", "edition" : "2011" } { "author" : "Steve Jones", "title" : "Boring Stuff", "edition" : "2010" } { "author" : "Ben Johnson", "title" : "Other Stuff", "edition" : "2010" } What should I do I want to find only the latest edition of each book? In other words: I want to get a

Getting Distinct values of multiple values in Mongodb

廉价感情. 提交于 2021-02-07 18:16:56
问题 Let's imagine I have the following collection of books (Edited out the ID field for compactness): { "author" : "Steve Jones", "title" : "Fun Stuff", "edition" : "2010" } { "author" : "Steve Jones", "title" : "Fun Stuff", "edition" : "2011" } { "author" : "Steve Jones", "title" : "Boring Stuff", "edition" : "2010" } { "author" : "Ben Johnson", "title" : "Other Stuff", "edition" : "2010" } What should I do I want to find only the latest edition of each book? In other words: I want to get a

Mongo find value with unknown parent key

徘徊边缘 提交于 2021-02-07 09:24:29
问题 I am looking for a value in a Mongo table where its parent key might not have a descriptive or known name. Here is an example of what one of our documents looks like. { "assetsId": { "0": "546cf2f8585ffa451bb68369" }, "slotTypes": { "0": { "usage": "json" }, "1": { "usage": "image" } } } I am looking to see if this contains "usage": "json" in slotTypes, but I can't guarantee that the parent key for this usage will be "0". I tried using the following query without any luck: db.documents.find(

MongoDB query to slow when using $or operator

守給你的承諾、 提交于 2021-02-07 04:15:48
问题 I'm trying to make this query to my collection Audios var querySlow = { "palabra": { $regex: "^" + keywords, "$options": "i" }, $or: [{ "_p_pais": { $in: interested_accents } }, { "languageCodeTatoeba": { $in: interested_accents_tatoeba } }] }; // takes 20 seconds This is actually really really slow but if I remove any of the $or , it is very very fast , for example: var queryFast1 = { "palabra": { $regex: "^" + keywords, "$options": "i" }, $or: [{ "_p_pais": { $in: interested_accents } }] };

MongoDB query to slow when using $or operator

不问归期 提交于 2021-02-07 04:15:04
问题 I'm trying to make this query to my collection Audios var querySlow = { "palabra": { $regex: "^" + keywords, "$options": "i" }, $or: [{ "_p_pais": { $in: interested_accents } }, { "languageCodeTatoeba": { $in: interested_accents_tatoeba } }] }; // takes 20 seconds This is actually really really slow but if I remove any of the $or , it is very very fast , for example: var queryFast1 = { "palabra": { $regex: "^" + keywords, "$options": "i" }, $or: [{ "_p_pais": { $in: interested_accents } }] };

MongoDB query to slow when using $or operator

孤人 提交于 2021-02-07 04:14:25
问题 I'm trying to make this query to my collection Audios var querySlow = { "palabra": { $regex: "^" + keywords, "$options": "i" }, $or: [{ "_p_pais": { $in: interested_accents } }, { "languageCodeTatoeba": { $in: interested_accents_tatoeba } }] }; // takes 20 seconds This is actually really really slow but if I remove any of the $or , it is very very fast , for example: var queryFast1 = { "palabra": { $regex: "^" + keywords, "$options": "i" }, $or: [{ "_p_pais": { $in: interested_accents } }] };

How do I validated array of objects using mongodb validator?

浪尽此生 提交于 2021-02-07 04:10:06
问题 I have been trying to validate my data using the validators provided by MongoDB but I have run into a problem. Here is a simple user document which I am inserting. { "name" : "foo", "surname" : "bar", "books" : [ { "name" : "ABC", "no" : 19 }, { "name" : "DEF", "no" : 64 }, { "name" : "GHI", "no" : 245 } ] } Now, this is the validator which has been applied for the user collection. But this is now working for the books array which I am inserting along with the document. I want to check the

MongoDB Spark Connector - aggregation is slow

天涯浪子 提交于 2021-02-06 12:50:36
问题 I am running the same aggregation pipeline with a Spark Application and on the Mongos console. On the console, the data is fetched within the blink of an eye, and only a second use of "it" is needed to retrieve all expected data. The Spark Application however takes almost two minutes according to the Spark WebUI. As you can see, 242 tasks are being launched to fetch the result. I am not sure why such an high amount of tasks is launched while there are only 40 documents being returned by the