mongodb-query

How to do a query using dot( . ) through Mongoose in Node.js and How to add an empty array

[亡魂溺海] 提交于 2019-12-13 18:31:58
问题 I have the following schema: var userSchema = new Schema({ userID: Number, userName: String, userEmail: String, teams:Array, socialMedias: { fbUID: String, googleUID: String, twitter: String } }); First, How can I add an empty array? Is it right the way I am doing in the following? teams:{}, Second, I am trying to do a query using Mongoose in my Node.js but I am getting an error in the dot ('.'): This is my document I am saving: var user = new users({ userID: id, //give the id of the next

How to index unknown fields of a known field in PyMongo?

ぃ、小莉子 提交于 2019-12-13 18:28:44
问题 I am trying to find unique words in millions of tweets and also I want to keep where each word appears. In addition to that, I am also grouping the words by their initial. Here is a sample code: from pymongo import UpdateOne # connect to db stuff for word in words: # this is actually not the real loop I've used but it fits for this example # assume tweet_id's and position is calculated here initial = word[0] ret = {"tweet_id": tweet_id, "pos": (beg, end)} # additional information about word

Same field error in aggregation _id

社会主义新天地 提交于 2019-12-13 18:18:55
问题 I have a collection in mongodb like this format : "_id" : ObjectId("542d5256372943d9e000fc42"), "_class" : "com.bedas.ays.mongo.dto.AboneAriza", "AdSoyad" : "AKIN COBAN", "aimid" : 100009, "CepTelefon" : "5332234401", "Telefon" : "0", "fiderid" : 101383, "kofrano" : NumberLong(444454), "tcNo" : "26402622688", "tmno" : { "trafoNo" : 21649, "trafoname" : "21450 BÜYÜKŞEHİR FİDERİ-->21646 BEYKOP 2.BÖLGE" }, "ilce" : { "ilceUavt" : 2051, "ilcename" : "BEYLİKDÜZÜ" }, "mahalle" : { "mahalleUavt" :

count the subdocument field and total amount in mongodb

老子叫甜甜 提交于 2019-12-13 18:06:21
问题 I've a collection with below documents: { "_id" : ObjectId("54acfb67a81bf9509246ed81"), "Billno" : 1234, "details" : [ { "itemcode" : 12, "itemname" : "Paste100g", "qty" : 2, "price" : 50 }, { "itemcode" : 14, "itemname" : "Paste30g", "qty" : 4, "price" : 70 }, { "itemcode" : 12, "itemname" : "Paste100g", "qty" : 4, "price" : 100 } ] } { "_id" : ObjectId("54acff86a81bf9509246ed82"), "Billno" : 1237, "details" : [ { "itemcode" : 12, "itemname" : "Paste100g", "qty" : 3, "price" : 75 }, {

How to do Left Join in DB (Mongo) [duplicate]

落爺英雄遲暮 提交于 2019-12-13 17:36:45
问题 This question already has answers here : How do I perform the SQL Join equivalent in MongoDB? (19 answers) Closed 9 months ago . I am new to Mongo! Please help me how to do left join in Mongo Sql Statement : Select * from TableA left Join TableB on (TableA.col1 = TableB.col1 AND TableB.col2 = "ABC") Please provide me the equivalent Mongo Query!!! Thanks In Advance ! 回答1: As of Mongo 3.2, you can do the equivalent to a left outer join with the new $lookup operator added to the aggregation

Aggregate with $sum in mongodb

让人想犯罪 __ 提交于 2019-12-13 17:23:33
问题 I have data in worksheets collection like below: /* 1 */ { "_id" : ObjectId("5c21d780f82aa31334ab6506"), "isBilling" : true, "hours" : 6, "userId" : ObjectId("5c1f38a1d7537d1444738467"), "projectId": ObjectId("5c1f38a1d7537d1444731234"); } /* 2 */ { "_id" : ObjectId("5c21d780f82aa31334ab6507"), "isBilling" : true, "hours" : 4, "userId" : ObjectId("5c1f38a1d7537d1444738493"), "projectId": ObjectId("5c1f38a1d7537d1444734567"); } /* 3 */ { "_id" : ObjectId("5c21e10fae07cc1204a5b647"), "isBilling

MongoDB - Error “Too many results for query, truncating output” with $geoNear

给你一囗甜甜゛ 提交于 2019-12-13 17:21:27
问题 I'm running a $geoNear query on my sharded cluster (6 nodes with 3 replica sets each of 2 shardsvr and 1 arbiter). I expect the query to return 1.1m documents. I am recieving only ~130.xxx documents. I am using the Java driver to issue the query and process the data (for now, I'm just counting the documents that get returned). I am using MongoDB 3.2.9 and the latest java driver. The mongod log shows the following error which is caused by the output document getting larger than 16MB: 2016-10

Mongo group with geospatial condition

一世执手 提交于 2019-12-13 17:03:57
问题 I have an issue when I try to aggregate results with a geospatial condition : db.users.group({ reduce: function(obj, prev) { prev.sums = { y_levels: prev.sums.y_levels + obj.current_y_level, x_levels: prev.sums.x_levels + obj.current_x_level, count: prev.sums.count + 1 } }, cond: {current_position: { $near: [56.553823, 8.565619, 10]}}, initial: { sums: { y_levels: 0, x_levels: 0, count: 0 } } }); produces : uncaught exception: group command failed: { "errmsg" : "exception: manual matcher

mongodb multiple groups in one result

Deadly 提交于 2019-12-13 16:40:05
问题 I have documents similar to this stored in mongodb { "_id":"transaction_id" "customer":"some customer", "order_date":Date('2011-01-01'), "delivery_date":Date('2011-01-15'), "amt":500.0, "qty":50 }, { "_id":"transaction_id" "customer":"some customer", "order_date":Date('2011-01-01'), "delivery_date":Date('2011-02-04'), "amt":500.0, "qty":50 } I am looking to do some aggregation for order date and delivery date to plot the total quantity of inventory being ordered and delivered to each customer

How to find MongoDB field name at arbitrary depth

余生颓废 提交于 2019-12-13 16:26:25
问题 I imported some sort-of sloppy XML data into a Mongo database. Each Document has nested sub-documents to a depth of around 5-10. I would like to find() documents that have a particular value of a particular field, where the field may appear at any depth in the sub-documents (and may appear multiple times). I am currently pulling each Document into Python and then searching that dictionary, but it would be nice if I could state a filter prototype where the database would only return documents