I was wondering about researching monetary values with the sample data. First I did a test with my local mongod. I am using db.version() 4.0.0. In the shell I run these lines
use qa
db.nums.insertOne( {name: 'John', val1: NumberDecimal("0.1"), val2: NumberDecimal("0.2") } );
db.nums.insertOne( {name: 'Jane', val1: 0.1, val2: 0.2 } );
Then the query
db.nums.find().pretty();
{
"_id" : ObjectId("5c4761f796df99b45ed013f5"),
"name" : "John",
"val1" : NumberDecimal("0.1"),
"val2" : NumberDecimal("0.2")
}
{
"_id" : ObjectId("5c4763c796df99b45ed013f6"),
"name" : "Jane",
"val1" : 0.1,
"val2" : 0.2
}
In node.js I then run
var MongoClient = require('mongodb').MongoClient;
async function connectToServer(whenDone)
{
var url = 'mongodb://127.0.0.1:27017/qa';
try {
var client = await MongoClient.connect(url, {useNewUrlParser: true });
var db = client.db('qa');
var coll = db.collection('nums');
var cursor = coll.find({});
var data = await cursor.toArray();
console.log('data', data);
}
catch (ex)
{
console.log(ex);
}
}
connectToServer( );
But the output is
data [
{ _id: 5c4761f796df99b45ed013f5, name: 'John', '': 0 },
{ _id: 5c4763c796df99b45ed013f6,
name: 'Jane',
val1: 0.1,
val2: 0.2 } ]
What’s up with the first record’s values not showing up?
Thank you.
Bill