mongodb-query

MongoDB/Mongoose unique constraint on Date field

前提是你 提交于 2019-12-13 14:28:27
问题 I have declared a unique index on a schema like so: var stateChangeEventSchema = mongoose.Schema({ client_timestamp: { type: Date, required: true, unique: true }, state: { type: String, required: true } }) And am able to insert a document with identical timestamps. I would expect a constraint violation. I thought it might be because it's on an embedded document, but I tried on a regular document, and it still allows it. What am I missing? Edit : I found the issue. I was failing to create

Mongodb - Multiple text index: Index key pattern too large error code 67

半城伤御伤魂 提交于 2019-12-13 13:22:14
问题 I have the following Mongodb database structure: { "_id" : "519817e508a16b447c00020e", "keyword" : "Just an example query", "rankings" : { results: { "1" : { "domain" : "example1.com", "href" : "http://www.example1.com/"}, "2" : { "domain" : "example2.com", "href" : "http://www.example2.com/"}, "3" : { "domain" : "example3.com", "href" : "http://www.example3.com/"}, "4" : { "domain" : "example4.com", "href" : "http://www.example4.com/"}, "5" : { "domain" : "example5.com", "href" : "http://www

How create a new array field with the aggregate framework

☆樱花仙子☆ 提交于 2019-12-13 12:04:04
问题 I'm starting to use mongoDb and I'm stuck with a simple use case. Let's say I've got a collection 'aCollection' with entries such as this: { _id: ObjectId(123), lat: 48,56623, long: 2,56332 } and I want to create a new collection with entries like this: { _id: ObjectId(123), lat: 48,56623, long: 2,56332, geometry : { type: "Point", coordinates: [48,56623, 2,56332] } } I thought about the aggregation framework: db.aCollection.aggregate([{$project: { _id: 1, lat: 1, long: 1, geometry: { type: {

Mongodb aggregate query, or too complex?

南楼画角 提交于 2019-12-13 09:29:25
问题 I have a dataset which looks like this: { uid: 1000000, from: "aaa", to: "bbb": timestamp: ISODate("2016-02-02T18:42:06.336Z") }, { uid: 1000000, from: "aaa", to: "bbb": timestamp: ISODate("2016-02-02T18:42:06.336Z") }, { uid: 1000000, from: "bbb", to: "ccc": timestamp: ISODate("2016-02-02T18:42:06.336Z") }, { uid: 1000000, from: "bbb", to: "ccc": timestamp: ISODate("2016-02-02T18:42:06.336Z") }, { uid: 2000000, from: "aaa", to: "bbb": timestamp: ISODate("2016-02-02T18:42:06.336Z") }, { uid:

Spring throws ConverterNotFound for range search on date in MongoDB

馋奶兔 提交于 2019-12-13 07:45:31
问题 I'm trying to do a range search on DateTime data format. The dates are being stored in Joda's DateTime format in the MongoDB. When I do a FIND query for a data greater than a given date, the ConverterNotFoundException is being thrown. Could someone please share information on why the conversation of Date object is being done to DateTime (Joda) &how can I possibly resolve this? Exception org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from

My mongodb/mongoose query conditions exclude themselves. Can you help me fixing that?

半城伤御伤魂 提交于 2019-12-13 07:01:43
问题 When user submits a content into my node.js app, he puts four things: start_date, his facebook username, text content and a flag, whether the content should be visible to everyone or only to his facebook friends. When user fetches content, he can get the public content from other users and the content from his facebook friends (even when they submitted their content only for their friends). I created a mongoose query that works correctly in this scenario. I do it like this: var query = Test

mongodb aggregation count items from two arrays

徘徊边缘 提交于 2019-12-13 06:48:35
问题 I'm trying to count the items from two arrays within the same model: Model: {_id:1 name:"fun", objectsTypeA: [ objectId_1 objectId_2 ], objectsTypeB: [ objectId_5 objectId_9 ] }, {_id:2 name:"boring", objectsTypeA: [ objectId_3 objectId_4 ], objectsTypeB: [] } I'm trying to get the following result: [ { name:"fun", id: 1, count:4 }, { name:"boring", id: 2, count: 2 ] What I got so far is this: Object.aggregate([ {$project: {_id:1, name:1, objectsTypeA:1}}, {$unwind:'$objectsTypeA'}, {$group:

MapReduce function in MongoDB - Grouping document by ID

别来无恙 提交于 2019-12-13 05:54:16
问题 I'm trying to learn MapReduce function in MongoDB. Instead of using an aggregation, I want to group documents in collection by key defined by myself using MapReduce function. My collection Cool is: /* 1 */ { "_id" : ObjectId("55d5e7287e41390ea7e83a55"), "id" : "a", "cool" : "a1" } /* 2 */ { "_id" : ObjectId("55d5e7287e41390ea7e83a56"), "id" : "a", "cool" : "a2" } /* 3 */ { "_id" : ObjectId("55d5e7287e41390ea7e83a57"), "id" : "b", "cool" : "b1" } /* 4 */ { "_id" : ObjectId(

MongoDB Stats for a particular search

谁都会走 提交于 2019-12-13 05:24:28
问题 I'd like to find a function within the MongoDB shell that will let me see how many items are in a particular query. For instance, I want to do something akin to: db.collection.find({category: "Cupcakes"}).stats() and see count, file size, that sort of thing. In MongoJS and other front-end implementations of MongoDb a query returns an object that you can perform a .length method on, like: db.collection.find({category: "Cupcakes"}, function(err, records){ console.log(records.length); // Shows

Rails & Mongoid - Merging multiple criteria

故事扮演 提交于 2019-12-13 05:23:54
问题 It took me a bit to figure this out and I'm sure others out there are curious how to do this as well.. I have a case where I need to run an .and() query using user input that I converted to an array. My problem was that the query was searching each and every field for BOTH words that was read in from the input. 回答1: So what I did is broke up the queries based on the fields. I.e. if you have the fields :tags, :story, :author you would have 3 queries, tag_query = Book.any_in(:tags => @user