minimongo

MongoDB - Project only the matching element in an array

混江龙づ霸主 提交于 2020-01-21 12:05:08
问题 How could I get one element from array from Mongo document with following structure: { array : [ {type: 'cat', name: 'George'} {type: 'cat', name: 'Mary'} {type: 'dog', name: 'Steve'} {type: 'dog', name: 'Anna'} ] } For example I need to get Steve, in this case result must looks so: { array : [ {type: 'dog', name: 'Steve'} ] } or so: {type: 'dog', name: 'Steve'} I know how make it while publishing but I need to make it on client side where whole array is available, I could return this value

How does Meteor create a unique MongoDB _id on the client side?

好久不见. 提交于 2020-01-16 02:51:08
问题 According to Meteor docs about the Mongo.Collection.insert() function, insert will generate a unique ID for the object you pass, insert it in the database, and return the ID. It also works asynchronously: If you do provide a callback, insert still returns the ID immediately. Is there any guarantee that the generated _id is globally unique? How does Meteor's Minimongo generate such an _id on the client side? 回答1: As Meteor is open source you can see exactly how this is done. README for random

Returning subdocument array through Meteor / Mongo

家住魔仙堡 提交于 2020-01-05 15:20:25
问题 I'm having a little trouble returning and displaying tags that I'm adding to a subdocument. I have no problem adding tags, but want to put a label on the item for each tag. I simply can't find a resource that helps me return the items in an array within a subdocument. I think it's all the helper where I'm stuck - basically the syntactically correct way to write "Items.(this._id).itemTags.find();" :) Oh - and I've cut out a lot of the HTML and JS, but, yes, everything else is working fine. The

Returning subdocument array through Meteor / Mongo

六眼飞鱼酱① 提交于 2020-01-05 15:18:03
问题 I'm having a little trouble returning and displaying tags that I'm adding to a subdocument. I have no problem adding tags, but want to put a label on the item for each tag. I simply can't find a resource that helps me return the items in an array within a subdocument. I think it's all the helper where I'm stuck - basically the syntactically correct way to write "Items.(this._id).itemTags.find();" :) Oh - and I've cut out a lot of the HTML and JS, but, yes, everything else is working fine. The

How to use $min mongo query in Meteor.js?

ε祈祈猫儿з 提交于 2019-12-25 02:47:06
问题 I'm basically trying to create a filter that only displays accounts that have more than one post. return tags.find([{owner: this.userId, count: { $min: 1}}]); It ends up returning nothing. I tried using .min() and other stuff as well. I believe its a standard Mongo query and am wondering if there is a Meteor-specific issue? 回答1: The standard Mongo query for that would use $gt: tags.find({owner: this.userId, count: {$gt: 1}}); 来源: https://stackoverflow.com/questions/24346489/how-to-use-min

Minimongo errors when I try to update a document containing an array

混江龙づ霸主 提交于 2019-12-24 17:23:52
问题 I'm having trouble updating an array that is contained in a document using angular-meteor. Minimongo throws an error documentMatches needs a document . The document that throws this error on update is shown below. One thing it contains is an array of _id s. This array contains the display order of some certain documents. It looks like this: { _id:"...", profileQuestions:{ profileQuestionsOrder:["jqKMp7rzsZApauwYE","jakehILKehpkdhj"] } } I have attached this using $scope.meteorObject to a

Can meteor mongo driver handle $each and $position operators?

落爺英雄遲暮 提交于 2019-12-22 02:48:54
问题 I work on a meteor application with meteor bundle up to date. I want to reposition an item within a mongo document array. To achieve that, I $pull it out of the array, and then $push it at a specific index position according to mongoDB documentation. MyCollection.update({_id: my_doc.id}, { $push: { my_array: { $each:[my_item.id], $position:index } } } ) Meteor/Mongo throws the following error: update failed: MongoError: Can't canonicalize query: BadValue unknown top level operator: $each I

Minimongo Error on Serverside Meteor Script?

▼魔方 西西 提交于 2019-12-13 19:23:01
问题 I'd like to push elements to a mongo array, and I have this query which should would with the current version of meteor mongo (2.6.7). This is the query: Coll.upsert({},{ $push: { 'events': { $each: [{'id': new Mongo.ObjectID, 'start':startDate, ... }], $sort: {'start': 1} } }}); ...And here is the minimongo error... Printed to the server console! I20151117-13:51:54.730(11)? Exception while invoking method 'addReservationTimeslot' MinimongoError: $sort requires $slice to be present I20151117

MongoDB-like JS library to store objects in client side indexedDB?

假装没事ソ 提交于 2019-12-12 07:03:35
问题 Given the following localStorage code (jsfiddle) : // my new information var data = {character: "中", totalMistakes: 0}; var han = data.character; // create localStorage; Unpack, update, repackage knol /* **** THIS IS THE SECTION TO CONVERT **** */ localStorage.knol = '{}'; // create pseudo object, as string var knol = JSON.parse(localStorage.knol) knol[han] = data; localStorage.knol = JSON.stringify(knol); // Print to check if all went well. console.log('data: ',data) console.log('han: ',han)

Sort and limit not working with Mongo + Meteor

心已入冬 提交于 2019-12-11 16:11:32
问题 This is my publish.js file in which I publish my collection: const tags = Tags.find({title: { $regex: `.*${searchString}.*`, $options: 'i' }}, { sort: { counts: -1 }, limit: 3 }); console.log(tags.count()); return tags; And this is my components which is subscribing to this collection: this.tagsSubscription = this.subscribe('tags', () => [this.tag], function (err) { that.tags = Tags.find().fetch(); }); So with this I get 2 different errors: sort and limit are not working: I sometimes get more