mongodb-query

Aggregate multiple arrays into one huge array with MongoDB

萝らか妹 提交于 2019-12-11 03:03:47
问题 I got a collection with documents such as those: { "_id": 0, "pictures": [ { "path": "/path/to/first/picture.jpg", "web": "true" }, { "path": "/path/to/second/picture.jpg", "web": "true", } ], "logos": [ { "path": "/path/to/first/logo.jpg", "web": "true" }, { "path": "/path/to/second/logo.jpg", "web": "false", } ] } { "_id": 1, "pictures": [ { "path": "/a/bit/weird/path/to/picture.jpg", "web": "false" }, { "path": "/another/weird/path/to/picture.jpg", "web": "false", } ], "logos": [ { "path":

Mongo update of subdocs

只愿长相守 提交于 2019-12-11 03:02:22
问题 I seem to have run into a roadblock while using MongoDB, and would like to know if there is anyway around it without having to modify my database structure. Right now my database structure is as follows: Company= { _id:1, properties:[ { property_id: 1 tags : [ { tag_id: 1 tag_value: 1000 channels: [ { channel_id:1 channel_name:"test1" }, { channel_id:2 channel_name:"test2" }] }, { tag_id:2 tag_value: 2500 channels: [ { channel_id:2 channel_name:"test2" }, { channel_id:3 channel_name:"test3" }

MongoDB full text search with haskell driver

陌路散爱 提交于 2019-12-11 02:58:18
问题 Is there a possibility to use the full text search of mongoDB with the haskell driver? I found the 'runCommand' in the haskell API, but it expects a Document as parameter. That's fine for all the other commands that mongodb can run, but the syntax for a text command is: db.collection.runCommand( "text", {search : "something"}) So I don't know how I'll get the "text" as first parameter in front of the Document. Thanks 回答1: The text -command can be written in another structure: { text: your

MongoDb aggregation

帅比萌擦擦* 提交于 2019-12-11 02:46:30
问题 How to write simial query using mongdoDb aggregation select count(*) as ccount from a group by a.someField order by ccount desc limit 1 Using group function in mondoDb, I want to group my collection by specific key and return 1 row, which occurs more often Code below in Java, return list, that was apply group by on field someField and return collection of elements, where every element has 2 fields, "someField" and "count" (number of occurrence) I would like to avoid second iteration on client

Morphia is there a difference between fetch and asList in performance wise

混江龙づ霸主 提交于 2019-12-11 02:29:40
问题 We are using morphia 0.99 and java driver 2.7.3 I would like to learn is there any difference between fetching records one by one using fetch and retrieving results by asList (assume that there is enough memory to retrieve records through asList ). We iterate over a large collection, while using fetch I sometimes encounter cursor not found exception on the server during the fetch operation, so I need to execute another command to continue, what could be the reason for this? 1-)fetch the

Express MongoDB find() based on _id field

偶尔善良 提交于 2019-12-11 02:19:01
问题 So In my express app, I am trying to find() based on my _id field. See my MongoDB record below. { "_id": { "$oid": "58c2a5bdf36d281631b3714a" }, "title": "EntertheBadJah", "subTitle": "Lorem ipsum dolor", "thmbNailImg": "", "headerImg": "", ... BLAH BLAH BLAH When I use .find( _id: id ) , my id param = 58c2a5bdf36d281631b3714a . How would I convert / use this to get my MongoDB record? Here is my Express call: //GET ARTICLE app.get('/api/article', (req, res) => { var id = req.query.id var

Object.keys, how to get a list of keys in mongodb

為{幸葍}努か 提交于 2019-12-11 02:13:25
问题 { "_id": "1", "style": "13123", "category": "dress", "colors": { "Black": { "prestock": 50, "instock": 60, "inactive": 0 }, "Blue": { "prestock": 30, "instock": 0, "inactive": 0 }, "Red": { "prestock": 10, "instock": 60, "inactive": 0 } } } i have above json, i need to access to prestock, instock, and inactive. but colors' value will change depending on styles. for example: { "_id": "2", "style": "14321", "category": "top", "colors": { "Green": { "prestock": 50, "instock": 60, "inactive": 0 }

Mongodb group and push with empty arrays

醉酒当歌 提交于 2019-12-11 02:09:28
问题 I'm having a problem with a group when there is an array that could be empty . The collection could be like this: { "_id" : "Contract_1", "ContactId" : "Contact_1", "Specifications" : [ ] } { "_id" : "Contract_2", "ContactId" : "Contact_2", "Specifications" : [ { "Description" : "Descrizione1", "VehicleId" : "Vehicle_1", "Customizations" : [ { "Description" : "Random furniture", "ContactId" : "Contact_5" }, { "Description" : "Random furniture 2", "ContactId" : "Contact_3" } ] }, {

Limit number of values in a field using MongoDB

空扰寡人 提交于 2019-12-11 01:58:52
问题 My collection has an array of values, but I'd like to retrieve only the last X. Example: db.collection.find({ "array": [0,1,2,3,4,5] }) And I'd like to query the last 3. How would I go about that? I'm using MongoDB and this is meant for a Meteor application. 回答1: You need to use the $slice operator. db.collection.find( { /* filter */ }, { "array": { "$slice": -3 } } ); 来源: https://stackoverflow.com/questions/34228375/limit-number-of-values-in-a-field-using-mongodb

MongoDB - descending index weird behavior

瘦欲@ 提交于 2019-12-11 01:54:22
问题 I have this test collection in my test database. [test] 2014-02-11 18:01:33.970 >>> db.test.find (); { "_id" : ObjectId("52faa8a695fa10cc7d2b7908"), "x" : 1 } { "_id" : ObjectId("52faa8ab95fa10cc7d2b7909"), "x" : 5 } { "_id" : ObjectId("52faa8ad95fa10cc7d2b790a"), "x" : 15 } { "_id" : ObjectId("52faa8b095fa10cc7d2b790b"), "x" : 25 } { "_id" : ObjectId("52faa8b795fa10cc7d2b790c"), "x" : [ 5, 25 ] } If I create an ascending index on the x field with [test] 2014-02-11 18:01:50.615 >>> db.test