mongo-collection

How to view or modify collation options set on a MongoDB collection?

让人想犯罪 __ 提交于 2021-01-27 14:13:14
问题 How do you modify the options that we set on a collection at the time of creation? And how do we view the options already set? If we see the collation option for example, I create a collection like this: db.createCollection("words", {collation : {locale :"es", strength : 2}}); And add few documents: db.words.insertOne({text : "Résumé"}); db.words.insertOne({text : "Resume"}); db.words.insertOne({text : "résumé"}); db.words.insertOne({text : "resume"}); How do I change the strength of the

Can a MongoDB collection have inside it another collection?

妖精的绣舞 提交于 2020-01-21 04:19:04
问题 I need to store a recursive tree structure. A linked list. So all the objects are the same. Each has a pointer to a parent object and each has an array of child objects. Can I store such a structure in Mongo. i.e. A Mongo collection of parent objects, each object holds within it a Mongo collection of child objects. $a = $MyCollection->findOne(**some conditions)->Childs->find(...) 回答1: You cant store collections in collections. But you can store ids that reference objects in other collections.

Creating new Meteor collections on the fly

两盒软妹~` 提交于 2019-12-28 13:57:30
问题 Is it possible to create new Meteor collections on-the-fly? I'd like to create foo_bar or bar_bar depending on some pathname which should be a global variable I suppose (so I can access it throughout my whole application). Something like: var prefix = window.location.pathname.replace(/^\/([^\/]*).*$/, '$1'); var Bar = new Meteor.Collection(prefix+'_bar'); The thing here is that I should get my prefix variable from URL, so if i declare it outside of if (Meteor.isClient) I get an error:

How to do upsert using jongo?

吃可爱长大的小学妹 提交于 2019-12-23 04:06:30
问题 I have a users table/collection and would like to upsert a user - update a user if exists or add a new one if still not exists. Structure below. By "exists", I mean having some external ID. In this case, googleId . How can I do it using Jongo library? Thanks. public class User { public String _id; public String email; public String givenName; public String familyName; public String googleId; } 回答1: Considering having a user with an already loaded googleId (passed google auth), and I'd like to

Meteor: There is no route for the path error. how to access SINGLE article within a nested object

妖精的绣舞 提交于 2019-12-12 03:39:11
问题 I have an array of 10 objects 'categories' and each category has sub objects such as posts within that category. This is how it looks. I access the category list like this. <template name="CategoriesMain"> {{#each articles}} <li> <a href="/unfiltered/{{_id}}"><h2>{{name}}</h2></a> </li> {{/each}} </ul> </template> this link <a href="/unfiltered/{{_id}}"><h2>{{name}}</h2></a> accesses the 'posts' list within the category which looks like this <template name="CategoriesSingle"> <h1>This is a

How to add collection name in the output of map reduce job to get all the keys in the collection with collection name .my code is like

拜拜、爱过 提交于 2019-12-12 02:53:41
问题 var allCollections = db.getCollectionNames(); for (var i = 0; i < allCollections.length; ++i) { var collectioname = allCollections[i]; if (collectioname === 'system.indexes') continue; db.runCommand( { "mapreduce" : collectioname, "map" : function() { for (var key in this) { emit(key, null); } }, "reduce" : function(key, stuff) { return null; }, "out":mongo_test + "_keys" }) } output { "_id" : "_id", "value" : null } { "_id" : "collection_name", "value" : null } { "_id" : "database", "value"

How to generate Mongodb documents recursively using mongocxx c++ driver?

霸气de小男生 提交于 2019-12-11 01:48:57
问题 How to generate Mongodb documents recursively using mongocxx c++ driver? 1. I use mongocxx c++ driver v.3 and c++11. 2. Here is my main.cpp method, which parses hex string and generate mongocxx code like this: console:$ ./main dissect 0x160301012c01000128030340c70e243001b96d8c and the output: << "MainType" << bsoncxx::builder::stream::open_document << "TLSRecord" << bsoncxx::builder::stream::open_document << "type"<< "16" << "version"<< "0301" << "length"<< "012C" << "hsMsg" << bsoncxx:

How to do upsert using jongo?

那年仲夏 提交于 2019-12-08 15:14:35
I have a users table/collection and would like to upsert a user - update a user if exists or add a new one if still not exists. Structure below. By "exists", I mean having some external ID. In this case, googleId . How can I do it using Jongo library? Thanks. public class User { public String _id; public String email; public String givenName; public String familyName; public String googleId; } Considering having a user with an already loaded googleId (passed google auth), and I'd like to upsert it to mongoDB, using Jongo: // Init MongoClient mongoClient = new MongoClient("localhost", 27017);

Mongodb Subdocument Date Range Returns Wrong Results

时间秒杀一切 提交于 2019-12-06 12:18:59
问题 first time in Stackoverflow. I'm trying to run a date range query on an array collection but Mongo Shell returning irrelevant documents witch doesn't match my criteria. It doesn't matter i'm doing the query trough PHP drivers, Doctrine Mongodb Query-builder or Mongo Shell. Here is my query: db.deals.find( { "total_sold.created_at": { $gt: new ISODate("2014-03-05T00:00:00Z"), $lt: new ISODate("2014-03-05T23:59:00Z") } }).limit(1).pretty() And here is the result: { "_id" :

Mongodb Subdocument Date Range Returns Wrong Results

我怕爱的太早我们不能终老 提交于 2019-12-04 19:45:33
first time in Stackoverflow. I'm trying to run a date range query on an array collection but Mongo Shell returning irrelevant documents witch doesn't match my criteria. It doesn't matter i'm doing the query trough PHP drivers, Doctrine Mongodb Query-builder or Mongo Shell. Here is my query: db.deals.find( { "total_sold.created_at": { $gt: new ISODate("2014-03-05T00:00:00Z"), $lt: new ISODate("2014-03-05T23:59:00Z") } }).limit(1).pretty() And here is the result: { "_id" : "1241412fb99a11a0bc70032a2cb6059b", "total_sold" : [ { "some_field": "value", "created_at" : ISODate("2014-02-13T15:48:35Z")