Consider the following code that I use to retrieve data from my local MongoDB server.
var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Binary = require('mongodb').Binary,
GridStore = require('mongodb').GridStore,
Code = require('mongodb').Code,
BSON = require('mongodb').pure().BSON,
assert = require('assert');
var db = new Db('test', new Server('localhost', 27017));
db.open(function(err, db) {
db.createCollection('simple_limit_skip_find_one_query', function(err, collection) {
assert.equal(null, err);
collection.insert([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1}, function(err, result) {
assert.equal(null, err);
collection.findOne({a:1}, {fields:{b:1}}, function(err, doc) {
});
});
});
});
Now I want to rename the field name when receiving only (not in the database), for example, with the above code, I have a field with the name bin the returned object docI want it to be baseIDinsteadb
Is there any way to do this?
Note. I cannot decide on a restored object docto rename a field, such as renaming a JSON key. I want it to be requested and MongoDB will be the same.