Questions tagged [mongo-collection]

110 questions
380
votes
25 answers

How to select a single field for all documents in a MongoDB collection?

In my MongoDB, I have a student collection with 10 records having fields name and roll. One record of this collection is: { "_id" : ObjectId("53d9feff55d6b4dd1171dd9e"), "name" : "Swati", "roll" : "80", } I want to retrieve the field…
Shipra Swati
  • 3,999
  • 2
  • 14
  • 7
298
votes
25 answers

How to copy a collection from one database to another in MongoDB

Is there a simple way to do this?
EasonBlack
  • 4,196
  • 4
  • 21
  • 24
59
votes
8 answers

Clone a collection in MongoDB

I want to clone a MongoDB collection and save it on the same server with a different name. So for example right now I have the following collections: demo1.categories, demo1.users and demo2.users. I want to have a "demo2.categories" which is…
Daryna
  • 749
  • 1
  • 7
  • 11
17
votes
11 answers

mongo-connect error with mongo-connect(session)

After searching around about it, I can't find any solution or mistake in my code about this error. I've got my app.js files inside my node JS application with the mongo-connect declaration : const MongoStore = require('connect-mongo')(session) And…
Souhail Mohamed
  • 273
  • 1
  • 3
  • 10
12
votes
2 answers

Can a MongoDB collection have inside it another collection?

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…
Itay Moav -Malimovka
  • 52,579
  • 61
  • 190
  • 278
8
votes
2 answers

creating unique index in mongoDB

I am using a java program for mongo db insertion trying to create a unique index for a field. product_src is a field in my collection and I want to set it as unique index for avoiding the duplicate insertion. I am trying the following code but…
sarath
  • 455
  • 1
  • 11
  • 26
7
votes
1 answer

How to merge two databases of mongoDB present in two different computers?

I am using mongoDB to store the data of a particular website. Since two of us are working, we are using our own computer for the job. Both the computer has a database website_data and a collection in that database webpages. Now for some analysis,…
Dibya Jyoti Roy
  • 133
  • 1
  • 2
  • 9
7
votes
4 answers

Create Collection in MongoDB Using Java

i want to create collection in mongodb using java.The below is the code i worked with.I can connect to database.But Collection is not happening..please help me import com.mongodb.MongoClient; import com.mongodb.DB; import…
user3219005
  • 83
  • 1
  • 2
  • 8
6
votes
2 answers

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

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 :…
Andrew Nessin
  • 1,206
  • 2
  • 15
  • 22
4
votes
1 answer

MongoDB lookup Algorithmic Complexity

What is the big-o complexity of MongoDB lookup operation? Say I have n records in my MongoDB collection 'A', And n records in collection 'B', each B's document have foreign _id of A, and one specific tag eg "preOrder","directOrder", "pendingOrder"…
4
votes
1 answer

MongoDb Update in PHP

I have one collection test_posts in which there are certain records. There is field called 'is_published' which has either 1 or 0 value. Based on which I am showing the content on end user side. I can show the content but for update there is some…
Pranav
  • 143
  • 1
  • 3
  • 15
4
votes
2 answers

Creating new Meteor collections on the fly

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…
errata
  • 5,695
  • 10
  • 54
  • 99
3
votes
0 answers

How to add a mongo id from one collection as a foreign key in another collection

In my Spring boot application, I have collection of Todos and a collection of Courses. In the view of the application, I return the collection of courses and display whatever course I need. The Todos are stored as 1 list which represents all the…
DevRight
  • 345
  • 1
  • 6
  • 25
3
votes
1 answer

How to connect to remote MongoDB with mongo-connector?

How can I connect to a MongoDB cluster on Mongo Atlas using mongo-connector? I have tried to connector to my cluster with the following commands: First attempt sudo mongo-connector -m…
hbd
  • 674
  • 7
  • 21
3
votes
2 answers

Using "from" as a kwarg key in pymongo's runcommand

I am attempting to use pymongo to clone a collection from a remote mongo instance, from the documentation cloning a collection requires the cloneCollection command, { cloneCollection: "", from: "", query: { } } and to…
Yogesh Mangaj
  • 3,200
  • 6
  • 32
  • 45
1
2 3 4 5 6 7 8