キーでMongoDBコレクションの子を取得するにはどうすればよいですか?
MongoDBのコレクションの子を取得するには、find()を使用します。ドキュメントを使用してコレクションを作成しましょう-
> db.demo305.insertOne(
... {
... _id: 101,
... FirstName : 'Chris',
... details : {
... "0":"102",
... "1":"10001"
... }
... }
...);
{ "acknowledged" : true, "insertedId" : 101 }
> db.demo305.insertOne(
... {
... _id: 102,
... FirstName : 'David',
... details : {
... "0":"103",
... "1":"10002"
... }
... }
...);
{ "acknowledged" : true, "insertedId" : 102 } find()メソッドを使用してコレクションからすべてのドキュメントを表示する-
> db.demo305.find();
これにより、次の出力が生成されます-
{ "_id" : 101, "FirstName" : "Chris", "details" : { "0" : "102", "1" : "10001" } }
{ "_id" : 102, "FirstName" : "David", "details" : { "0" : "103", "1" : "10002" } } 以下は、キーによってMongoDBコレクションの子を取得するためのクエリです-
> db.demo305.find({_id:102},{'details.0':1}); これにより、次の出力が生成されます-
{ "_id" : 102, "details" : { "0" : "103" } } -
MongoDBコレクションから一意の値を取得するにはどうすればよいですか?
一意の値を取得して重複を無視するには、MongoDBでdistinct()を使用します。個別の()は、単一のコレクション全体で指定されたフィールドの個別の値を検索し、結果を配列で返します。 ドキュメントを使用してコレクションを作成しましょう- > db.demo704.insertOne({"LanguageCode":"hi"}); { "acknowledged" : true, "insertedId" : ObjectId("5ea6ee
-
C#のStringDictionaryでキーのコレクションを取得します
StringDictionaryでキーのコレクションを取得するには、コードは次のとおりです- 例 using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ StringDictionary strDict1 = new StringDictionary(); strDict1.Add("