Last active
December 30, 2015 03:44
-
-
Save dineshsprabu/94dda75f27723043ebd1 to your computer and use it in GitHub Desktop.
Setting _id as raw String on Mongo from NodeJS (Solution: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The unwanted complication on monk ('_id' as HEX 12-24 bytes) can be handled by using native mongo driver */ | |
var MongoClient = require('mongodb').MongoClient; | |
/* values to be changed as per need */ | |
var input = {'_id':'string_value'}; | |
var collection_name = 'collection_name'; | |
var db_name = 'db_name'; | |
MongoClient.connect("mongodb://localhost:27017/"+db_name, function(err, db) { | |
if(err) { return console.dir(err); } | |
var collection = db.collection(collection_name); | |
collection.insert(input); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment