mongodb-query

optimizing query for $exists in sub property

只谈情不闲聊 提交于 2019-12-24 22:10:01
问题 I need to search for the existence of a property that is within another object. the collection contains documents that look like: "properties": { "source": { "a/name": 12837, "a/different/name": 76129 } } As you can see below, part of the query string is from a variable. With some help from JohnnyHK (see mongo query - does property exist? for more info), I've got a query that works by doing the following: var name = 'a/name'; var query = {}; query['properties.source.' + name] = {$exists: true

MongoDB query with nested structure [duplicate]

梦想与她 提交于 2019-12-24 19:19:59
问题 This question already has answers here : Retrieve only the queried element in an object array in MongoDB collection (11 answers) Closed last year . How can I query (in MongoDB) this nested json structure in order to get only the nested object which has the "position" value equal to "currentPosition" value? { "JobId": "123" "currentPosition" : NumberInt(18), "details" : [ { "position": NumberInt(18), "fname" : "Alexander", "lname" : "A", }, { "position": NumberInt(18), "fname" : "Doug", "lname

MongoDB nested array search using $map

浪子不回头ぞ 提交于 2019-12-24 19:18:43
问题 I have collection which contains nested array. I need to fetch the data based on below condition: empId : 19107 address.country: "AUS" group.primaryGroup.primary:"Y" group.subGroup.primarySubGroup.primary : "Y" Input: { "empId": "19107", "address": [ { "street": "no.12 wilson street", "country":"AUS" }, { "description": "No.32 watson street", "country":"CAN" } ], "mobile": 2387468238, "group": [ { "groupId": 75227, "primaryGroup": [ { "primary": "Y" }, { "primary": "N" } ], "subGroup": [ {

Get distinct nested document values from a collection in MongoDB using C#

本小妞迷上赌 提交于 2019-12-24 19:17:24
问题 This question involves getting distinct values of a nested document in Mongo DB using C#. I have a collection of documents, each document having the structure: { key1: value1, key2: value2, key3: { nestedKey1: nestedValue1, nestedKey1: nestedValue1 } } I need to query a list of distinct nestedKey1 values based on the value of key1 . I can do this (using a shell in Robomongo) by using the command: db.runCommand({distinct:'collection_name', key:'key3.nestedKey1', query: {key1: 'some_value'}})

LinqToMongo Inject

百般思念 提交于 2019-12-24 18:51:56
问题 I have a .NET app which uses MongoDB so I am using the Mongo C# driver. The driver version I am currently using is 1.9.2 and everything in my app works as expected. However I am trying to upgrade the Mongo driver to latest version 2.7.0 however I am having some issues getting some things working. The below Code snippet is where I am facing an issue with latest version of driver public IQueryable<Location> SearchByLocationDistance(double latitude, double longitude, double rangeInKm) { var

Copy a field from one collection to another in mongodb with foreign key as mixed type

ぐ巨炮叔叔 提交于 2019-12-24 17:47:41
问题 Although i have found a similar question on stackOverFlow MongoDB copy a field to another collection with a foreign key I want to copy a field name from userdetails collection to user collection where userId in userDetails equals _id in user. user collection { "_id" : ObjectId("5b97743bbff66e0be66283cc"), "username" : "mmi_superadmin", "accId" : "acc1" } { "_id" : "c21d580ea3ca5c7a1664bd5feb57f0c8", "username" : "client", "accId" : "acc1" } userDetail collection { "_id" : ObjectId(

Mongo query to sort by distinct count

冷暖自知 提交于 2019-12-24 16:03:53
问题 I have two fields 'company' and 'url'. I want to sort it by number of times distinct 'company' is occurring and then display three 'url' corresponding to that particular company. Data is stored like this: { "_id" : ObjectId("56c4f73664af6f7305f3670f"), "title" : "Full Stack Software Developer", "url" : "http://www.indeed.com/cmp/Upside-Commerce,-Inc./jobs/Full-Stack-Software-Developer-6e93e36ea5d0e57e?sjdu=QwrRXKrqZ3CNX5W-O9jEvRQls7y2xdBHzhqWkvhd5FFfs8wS9wesfMWXjNNFaUXen2pO-kyc_Qbr7-

Easier way to Update an Array with MongoDB

蓝咒 提交于 2019-12-24 15:24:14
问题 My mongoose collection looks something like: var followSchema = new Schema({ facebookId: {type: String, required: true}, players : [], fans: [], }); When a player wants to follow another user, I add that user's id into the players[] array. In order to achieve this I first look up the player's record: var myRecord = FollowModel.findOneAndUpdate( {facebookId: req.user.facebookId}, {$setOnInsert: {}}, {upsert: true, new : true} ); The above ensures that if the player doesn't exist, one is

MongoDB Aggregate Array with Two Fields

做~自己de王妃 提交于 2019-12-24 15:19:24
问题 I have vehicles collection with the following schema, all the articles are just general products (no child products included): { "_id" : ObjectId("554995ac3d77c8320f2f1d2e"), "model" : "ILX", "year" : 2015, "make" : "Acura", "motor" : { "cylinder" : 4, "liters" : "1.5" }, "products" : [ ObjectId("554f92433d77c803836fefe3"), ... ] } And I have products collection, some of them are general products related with warehouse sku's and some products are "son" products that fit in multiples general

Calling mongoose from react client side

二次信任 提交于 2019-12-24 14:06:00
问题 Yes, I know I should call it from server side. But the purpose is to invoke MongoDB strait from the react-redux app. It's like firebase serverless apps do. I write import mongoose from 'mongoose'; let mongoDB = 'mongodb://127.0.0.1/my_database'; mongoose.connect(mongoDB); mongoose.Promise = global.Promise; let db = mongoose.connection; db.on('error', console.error.bind(console, 'MongoDB connection error:')); And I get: TypeError: __ WEBPACK_IMPORTED_MODULE_6_mongoose___default.a.connect is