Hello !
I can not find a way to use timestamps with vibe.d mongodb, I basically want to have a field that is updated with current time on every update operation and be able to find records that has been updated since a certain timestamp value.
In SQL it's something like this:
create table atable(id integer primary key, data text, mdate datetime default CURRENT_TIMESTAMP);
insert into atable(data, mdate) values('avalue', CURRENTTIMESTAMP);
update atable set data='another value', mdate=CURRENTTIMESTAMP where id = 1;
select * from atable where mdate > '2014-12-12 00:00:00';
In vibe.d:
Mongo db = connectMongoDB(mongo_uri);
auto atable = db.getCollection("atable");
atable.insert(["data": "avalue", "mdate": ????);
atable.update(["data": "another value", "mdate": ???]);
atable.find(Bson(["mdate": ["$gt": "2014-12-12 00:00:00 ???"]]));
I want it in a generic way so I can make the "mdate" update in one place for all collections through a wrapper:
bool updateMongo(MondoDB db, string collectionname, string theid, string[string] record)
{
auto collection = db.getCollection(collectionname);
alias strrec = string[string];
str_rec[string] rec;
rec["$set"] = record;
rec["$currentDate"] = ["mdate": { "$type": "timestamp" }
]; //????????
collection.update(["id":Bson(BsonObjectID.fromString(theid))], record);
}
Thanks in advance for any help !