top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

I am writing scripts for the mongo shell, how can I get the ID of the inserted document?

0 votes
202 views
I am writing scripts for the mongo shell, how can I get the ID of the inserted document?
posted Mar 13, 2018 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
0 votes

I am trying to use the truncate feature within YCSB to cause the db to truncate the data set to allow multiple runs against the DB to see the same DB state in spite of previous runs inserts.
I am using -p truncate=true. Is this the correct way to cause a truncate in Mongo.

+1 vote

I am new to Node and Mongo, I was trying to connect to a mongo database in one file and export the database handler to many other files, so that I need not to connect to the database in all files which need a connection to it. Here is how I attempted to do it

// db.js
var client = require(mongodb).MongoClient
var assert = require(assert)
var url = mongodb://localhost:27017/test

client.connect(url, (err, db) => {
  assert.equal(err, null)
  module.exports = db
})

After exporting the db handler, I tried to access methods on it in another file as follows

var db = require(./db)
console.log(db.collection(col))

but it throws a TypeError, saying that db.collection is not a function. How can I access the methods on db handler in other files?

+3 votes

I would like to get the list of the database manage by on server through a single shell command, on UNIX. The objective is to be able to do a full export of all dbs for validation purposes.
Right now, I can see only two ways to do this.
- Start mongo, type show dbs, to a manual copy of the list and exit. I do not like this way as this requires several manual operations.
- Scan the files.*.0 in the db directory.
This works but is dependent on the format of the database.Is there any better way to list all the DBs managed by a server through a single command? I am using MongoDB 3.0.4 on Scientific Linux.

0 votes

Can we use mongo recommended snapshot i.e LVM snapshot across versions? i.e snapshot taken from v2.4.10 and restore it to v3.0.4.
We have tested the same and this works. Is this recommended by mongo?

...