ক্ষেত্র সংযুক্ত করতে, $concat অপারেটর ব্যবহার করুন। আসুন প্রথমে নথি-
সহ একটি সংগ্রহ তৈরি করি>db.concatenateFieldsDemo.insertOne({"StudentFirstName":"Adam","StudentLastName":"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ebf46d78f205348bc62e") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"John","StudentLastName":"Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ebfc6d78f205348bc62f") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"David","StudentLastName":"Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ec376d78f205348bc630") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"Sam","StudentLastName":"Williams"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ec436d78f205348bc631") }
Find() পদ্ধতির সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করার জন্য নিম্নলিখিত প্রশ্ন রয়েছে -
> db.concatenateFieldsDemo.find().pretty();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "_id" : ObjectId("5cd6ebf46d78f205348bc62e"), "StudentFirstName" : "Adam", "StudentLastName" : "Smith" } { "_id" : ObjectId("5cd6ebfc6d78f205348bc62f"), "StudentFirstName" : "John", "StudentLastName" : "Doe" } { "_id" : ObjectId("5cd6ec376d78f205348bc630"), "StudentFirstName" : "David", "StudentLastName" : "Miller" } { "_id" : ObjectId("5cd6ec436d78f205348bc631"), "StudentFirstName" : "Sam", "StudentLastName" : "Williams" }
−
ক্ষেত্রগুলি নির্বাচন এবং সংযুক্ত করার জন্য নিম্নলিখিত প্রশ্নগুলি রয়েছে৷> db.concatenateFieldsDemo.aggregate([ {$project:{"StudentFullName":{$concat: ["$StudentFirstName","/","$StudentLastName"]},"StudentFirstName":1,"StudentLastName":1}} ]);
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "_id" : ObjectId("5cd6ebf46d78f205348bc62e"), "StudentFirstName" : "Adam", "StudentLastName" : "Smith", "StudentFullName" : "Adam/Smith" } { "_id" : ObjectId("5cd6ebfc6d78f205348bc62f"), "StudentFirstName" : "John", "StudentLastName" : "Doe", "StudentFullName" : "John/Doe" } { "_id" : ObjectId("5cd6ec376d78f205348bc630"), "StudentFirstName" : "David", "StudentLastName" : "Miller", "StudentFullName" : "David/Miller" } { "_id" : ObjectId("5cd6ec436d78f205348bc631"), "StudentFirstName" : "Sam", "StudentLastName" : "Williams", "StudentFullName" : "Sam/Williams" }