Hya!
Long story short.
What I'm using:
I insert some amount of data (~35Mb nothing serious) every 30 mins via JSON file and I would like to add a custom field which is static for every document that have been inserted at one time.
(actually this a timestamp which is already generated by another server, unfortunately mongodb already reserved "timestamps" for it's own inner usage so that's why I'm here)
My code looks something like these
...
var toomuchJSONdata = [{
"name":"John",
"age":30,
}
{
"name":"Carl",
"age":25,
}{
"....":"....",
"....":"....",
}];
...
to-my.collection.insertMany(toomuchJSONdata)
...
So what's the best/easiest way to solve my problem? Or I'm moving in the wrong direction and it's much easier and better to add a custom "key":"value" for every JSON object? Like:
var toomuchJSONdata = [{
"name":"John",
"age":30,
"customkey":"customvalue"
}
By the way, how's better to store data in Mongo as Date or timestamp? (I'd like to store it, because I need to $aggregate data in future) What I have already done (..and still doing):
TL:DR In my case I solve this problem with this code which modifies my JSON data before .insering it to MongoDB:
var jsonObject = JSON.parse(body).files;
var ts = (jsonObject[0].lastModified); //form timestamp TODO if ts updated too long reresh timer for query
if (error) {
console.log(error);
}
else {
request(jsonObject[0].url, function(error, response, body){
var MarketData = JSON.parse(body).auctions;
MarketData.map(function (MarketData) {
MarketData.lastModified = ts;
});
Thanks to @Paul and @stackoverYC for inspiring me.
The reason why I can't just use $aggregate via mongoose (or other mongodb driver) because "timestamp" field is already reserved by mongodb for its own "inner-usage". So I call my new field as "lastModified"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.