上篇文章介绍了MongoDB的初级使用-----增加,删除和更新,这次来说查询
无条件查询
无条件查询,find()即为显示所有
MongoDB Enterprise > db.users.find()
{
"_id" : ObjectId("5e5fe640ded658ecc287bfe3"), "username" : "zhao", "password" : "123" }
{
"_id" : ObjectId("5e5fe646ded658ecc287bfe4"), "username" : "qian", "password" : "123" }
{
"_id" : ObjectId("5e5fe64aded658ecc287bfe5"), "username" : "sun", "password" : "123" }
{
"_id" : ObjectId("5e5fe64aded658ecc287bfe6"), "username" : "li", "password" : "123" }
{
"_id" : ObjectId("5e5fe650ded658ecc287bfe7"), "username" : "zhou", "password" : "123" }
{
"_id" : ObjectId("5e5fe650ded658ecc287bfe8"), "username" : "wu", "password" : "123" }
{
"_id" : ObjectId("5e5fe6a9ded658ecc287bfe9"), "username" : "zheng", "password" : "12345" }
{
"_id" : ObjectId("5e5fe6a9ded658ecc287bfea"), "username" : "wang", "password" : "123", "email" : "12345@qq.com" }
加pretty(),可让结果更具可读性
MongoDB Enterprise > db.users.find().pretty()
{
"_id" : ObjectId("5e5fe640ded658ecc287bfe3"),
"username" : "zhao",
"password" : "123"
}
{
"_id" : ObjectId("5e5fe646ded658ecc287bfe4"),
"username" : "qian",
"password" : "123"
}
{
"_id" : ObjectId("5e5fe64aded658ecc287bfe5"),
"username" : "sun",
"password" : "123"
}
{
"_id" : ObjectId("5e5fe64aded658ecc287bfe6"),
"username" : "li",
"password" : "123"
}
{
"_id" : ObjectId("5e5fe650ded658ecc287bfe7"),
"username" : "zhou",
"password" : "123"
}
{
"_id" : ObjectId("5e5fe650ded658ecc287bfe8"),
"username" : "wu",
"password" : "123"
}
{
"_id" : ObjectId