I'm creating an offline app that create users locally and when the app is online I want to sync the created users to my remote mongodb database. So my question is there any plugin preferably in angular that creates a local mongodb _id?
You can use any unique id for a _id field. However, if you do not specify _id field at all in your data, MongoDB will itself create a _id field with ObjectID type in documents.
Still, if you need to create ObjectId in your application, you can do it on the server.
It depends on the driver you are using for MongoDB connectivity.
If you are using NodeJS driver for MongoDB, then you can do it like this.
Reference
var ObjectID = require('mongodb').ObjectID;
var objectId = new ObjectID();
If you are using mongoose for MongoDB object modeling in NodeJS, then you can do it like this
Mongoose Reference for types
var mongoose = require('mongoose');
var id = mongoose.Types.ObjectId();
For Python MongoDB driver, refer this - pymongo ObjectId
I hope you can create ObjectId using other drivers as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With