値がMongoDBの特定の文字で終わるドキュメントを取得するにはどうすればよいですか?
以下は、MongoDBで値が特定の文字で終わるドキュメントを取得するための構文です
db.yourCollectionName.find({yourFieldName: {$regex: "yourEndingCharacter$"}}).pretty(); まず、ドキュメントを使用してコレクションを作成しましょう
>db.retrieveDocumentsWithEndsWithParticularCharacterDemo.insertOne({"StudentName":"Adam","StudentAge":25,"StudentCountryName":"LAOS"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9c45b32d66697741252456")
}
>db.retrieveDocumentsWithEndsWithParticularCharacterDemo.insertOne({"StudentName":"Sam","StudentAge":24,"StudentCountryName":"ANGOLA"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9c45c02d66697741252457")
}
>db.retrieveDocumentsWithEndsWithParticularCharacterDemo.insertOne({"StudentName":"Robert","StudentAge":21,"StudentCountryName":"AUS"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9c45cb2d66697741252458")
}
>db.retrieveDocumentsWithEndsWithParticularCharacterDemo.insertOne({"StudentName":"Chris","StudentAge":20,"StudentCountryName":"UK"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9c45d92d66697741252459")
}
>db.retrieveDocumentsWithEndsWithParticularCharacterDemo.insertOne({"StudentName":"Larry","StudentAge":23,"StudentCountryName":"US"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9c45eb2d6669774125245a")
} 以下は、find()メソッドを使用してコレクションからすべてのドキュメントを表示するためのクエリです
> db.retrieveDocumentsWithEndsWithParticularCharacterDemo.find().pretty();
これにより、次の出力が生成されます
{
"_id" : ObjectId("5c9c45b32d66697741252456"),
"StudentName" : "Adam",
"StudentAge" : 25,
"StudentCountryName" : "LAOS"
}
{
"_id" : ObjectId("5c9c45c02d66697741252457"),
"StudentName" : "Sam",
"StudentAge" : 24,
"StudentCountryName" : "ANGOLA"
}
{
"_id" : ObjectId("5c9c45cb2d66697741252458"),
"StudentName" : "Robert",
"StudentAge" : 21,
"StudentCountryName" : "AUS"
}
{
"_id" : ObjectId("5c9c45d92d66697741252459"),
"StudentName" : "Chris",
"StudentAge" : 20,
"StudentCountryName" : "UK"
}
{
"_id" : ObjectId("5c9c45eb2d6669774125245a"),
"StudentName" : "Larry",
"StudentAge" : 23,
"StudentCountryName" : "US"
} 以下は、MongoDBの特定の文字で値が終わるドキュメントを取得するためのクエリです。文字「S」で終わる値をチェックしています
> db.retrieveDocumentsWithEndsWithParticularCharacterDemo.find({StudentCountryName: {$regex: "S$"}}).pretty(); これにより、次の出力が生成されます
{
"_id" : ObjectId("5c9c45b32d66697741252456"),
"StudentName" : "Adam",
"StudentAge" : 25,
"StudentCountryName" : "LAOS"
}
{
"_id" : ObjectId("5c9c45cb2d66697741252458"),
"StudentName" : "Robert",
"StudentAge" : 21,
"StudentCountryName" : "AUS"
}
{
"_id" : ObjectId("5c9c45eb2d6669774125245a"),
"StudentName" : "Larry",
"StudentAge" : 23,
"StudentCountryName" : "US"
} -
MySQL SELECTを使用して列の値の最後に文字を追加しますか?
このためには、CONCAT()を使用して連結を実行する必要があります。 まずテーブルを作成しましょう- mysql> create table DemoTable766 (Name varchar(100)); Query OK, 0 rows affected (0.65 sec) 挿入コマンド-を使用して、テーブルにいくつかのレコードを挿入します mysql> insert into DemoTable766 values('John'); Query OK, 1 row affected (0.12 sec) mysql> insert into D
-
Javaを使用してMongoDBコレクションからすべてのドキュメントを取得するにはどうすればよいですか?
find()を使用して、MongoDBの既存のコレクションからドキュメントを取得できます メソッド。 構文 db.coll.find() どこで、 db はデータベースです。 coll ドキュメントを挿入するコレクション(名前)です 例 次のドキュメントを含むstudentsという名前のコレクションがMongoDBデータベースにあると仮定します- {name:"Ram", age:26, city:"Mumbai"} {name:"Roja", age:28, city:"Hyderaba