mongodb-query

MongoDb: how to search in multiple collections?

陌路散爱 提交于 2021-01-29 06:06:24
问题 I got this structure in my mongodb (2 collections: restaurant and cocktail ) restaurant {id=1001, name="Res1", coor=[12.392, 19.123], cocktail=[13, 0, 92]} cocktail {id=13, name="Capiroska"}, {id=167, name="Capirinha"}, {id=92, name="Negroni"}, {id=0, name="Martini"} Multiple restaurant s and multiple cocktail s, N:N relationship. My goal is to find which different cocktail s I can drink within a specified area. I've already written a query that finds all restaurants near my position like

How to get set of missing consecutive numbers array only has low and high mongodb

无人久伴 提交于 2021-01-29 05:04:29
问题 I am trying to get sets of having an array of missing consecutive numbers only has [low, high] Example, mongodb collection 'meta_import' has these numbers: [1,2,3,4,7,8,100,101,200,400,401,403] I want to get [[5,6], [9,99], [102,199], [201,399], [402]] I have tried: var pipe = [ {'$group' : {'_id' : null, min : {'$min' : "$num"}, max : {'$max' : "$num"}}}, {'$addFields' : {'rangeIds' : {'$range' : ["$min", "$max"]}}}, {'$lookup' : {'from' : "meta_import", localField : "rangeIds", foreignField

How to update string field in mongodb and manipulate string values?

拟墨画扇 提交于 2021-01-29 03:22:14
问题 I have a MongoDB collection with some documents that have a field called Personal.FirstName and another field call Personal.Surname. Some documents are messed up and have the persons first name and last name in both fields. For example there are some documents that have Personal.FirstName = 'John Doe' and Personal.Surname = 'John Doe'. I want to write a mongo update statement that will do the following: Find all of the documents that have a Personal section Find all of the documents where

How to update string field in mongodb and manipulate string values?

ぃ、小莉子 提交于 2021-01-29 03:17:44
问题 I have a MongoDB collection with some documents that have a field called Personal.FirstName and another field call Personal.Surname. Some documents are messed up and have the persons first name and last name in both fields. For example there are some documents that have Personal.FirstName = 'John Doe' and Personal.Surname = 'John Doe'. I want to write a mongo update statement that will do the following: Find all of the documents that have a Personal section Find all of the documents where

how to replace multiple occurrences of a phrase mongodb

假如想象 提交于 2021-01-28 23:33:13
问题 I am trying to replace multiple occurrences of the same phrase in the same field. Here is an example of the field 'imageUrl' contents: "imageUrl" : "https://cdn.test.com/s/files/1/0035/4671/0061/products/Screen_Shot_2019-12-13_at_12.47.01_pm_2000x.png?v=1576212956\n \n https://cdn.test.com/s/files/1/0035/4671/0061/products/Screen_Shot_2019-12-13_at_12.47.01_pm_2000x.png?v=1576212956\n \n \n" My current formula: { $match: { imageUrl: { $regex: "_2000x" }, brand: "Goat The Label" } }, {

how to replace multiple occurrences of a phrase mongodb

房东的猫 提交于 2021-01-28 23:29:52
问题 I am trying to replace multiple occurrences of the same phrase in the same field. Here is an example of the field 'imageUrl' contents: "imageUrl" : "https://cdn.test.com/s/files/1/0035/4671/0061/products/Screen_Shot_2019-12-13_at_12.47.01_pm_2000x.png?v=1576212956\n \n https://cdn.test.com/s/files/1/0035/4671/0061/products/Screen_Shot_2019-12-13_at_12.47.01_pm_2000x.png?v=1576212956\n \n \n" My current formula: { $match: { imageUrl: { $regex: "_2000x" }, brand: "Goat The Label" } }, {

Projecting results from MongoDb Find in F#

人走茶凉 提交于 2021-01-28 21:50:56
问题 I'm trying to query MongoDB using MongoDB.Driver and return a partial result using mongo projection. I've figured out how to query without projection, but not a partial result. This is my function for finding results: let Find<'a> collectionName (filterDefinition: FilterDefinition<'a>) = let collection = database.GetCollection<'a> collectionName collection.Find(filterDefinition).ToEnumerable() |> List.ofSeq This is an example of how I call it: let findByIdFilter id = Builders<MyModel>.Filter

Query mongoDB for a date between two dates misses some documents

白昼怎懂夜的黑 提交于 2021-01-28 18:02:46
问题 I have the following document in a collection name chats : { "_id" : 25281, "conversation" : [ { "time" : "1970-01-18T20:16:28.988Z" }, { "time" : "2018-11-09T18:43:09.297Z" } ], } For some reason this specific document is not returning in the below query, although similar documents are returning as expected. Here is the query: db.getCollection('chats').find({"conversation.1.time": { "$gte": ISODate("2018-11-09T00:00:00.000Z"), "$lt": ISODate("2018-11-10T00:00:00.000Z") } }) 回答1: This

MongoDB NodeJS Native Driver(mongodb) vs Mongo Shell Performance

一世执手 提交于 2021-01-28 11:49:31
问题 I have 10000 records in MongoDB in table1. Data is as below: "_id" : ObjectId("5d5e500cb89312272cfe51fc"), "cities" : [ { "cityid" : "5d5d2205cdd42d1cf0a92b33", "value" : "XYZ" }, { "cityid" : "5d5d2214cdd42d1cf0a92b34", "value" : "Rowcliffe" }, ], Query is as below: { $unwind: "$cities" }, { "$addFields": { "cities.cityid": { "$toObjectId": "$cities.cityid" } } }, { $lookup: { from: "cities", localField: "cities.cityid", foreignField: "_id", as: "docs" } }, So, here i lookup cityid in

How to Populate data using Mongodb Aggregate framework?

不打扰是莪最后的温柔 提交于 2021-01-28 11:32:30
问题 I have a current MongoDB Aggregate framework pipeline from a previous question and I am unable to add populate query to grab user profile by id. My code is below Product.aggregate([ { $group: { _id: { hub: "$hub", status: "$productStatus", }, count: { $sum: 1 }, }, }, { $group: { _id: "$_id.hub", counts: { $push: { k: "$_id.status", v: "$count", }, }, }, }, { $group: { _id: null, counts: { $push: { k: { $toString: "$_id" }, v: "$counts", }, }, }, }, { $addFields: { counts: { $map: { input: "