1
從mongo_dart的blog.dart中抽取樣本在將記錄添加到數據庫時,我希望打出一些強類型。任何幫助表示讚賞。Dart使用MongoDB強打字
Db db = new Db("mongodb://127.0.0.1/mongo_dart-blog");
DbCollection collection;
DbCollection articlesCollection;
Map<String,Map> authors = new Map<String,Map>();
db.open().chain((o){
db.drop();
collection = db.collection('authors');
collection.insertAll(//would like strongly typed List here instead
[{'name':'William Shakespeare', 'email':'[email protected]', 'age':587},
{'name':'Jorge Luis Borges', 'email':'[email protected]', 'age':123}]
);
return collection.find().each((v){authors[v["name"]] = v;});
}).chain((v){
print(">> Authors ordered by age ascending");
db.ensureIndex('authors', key: 'age');
return collection.find(where.sortBy('age')).each(
(auth)=>print("[${auth['name']}]:[${auth['email']}]:[${auth['age']}]"));
}).then((dummy){
db.close();
});
這很棒!讓我想起了Linq。 – basheps