MongoDB
 Computer >> コンピューター >  >> プログラミング >> MongoDB

MongoDBでNOTとANDを一緒に使用できますか?


はい、MongoDBではNOTとANDを一緒に使用できます。構文は次のとおりです

NOT X AND NOT Y = NOT (X AND Y)
Let us see the working of above syntax.
If both X and Y will be true then last result will be false.
If one of the operands gives result false then last result will be true.

以下は、ドキュメントを含むコレクションを作成するためのクエリです

> db.NotAndDemo.insertOne({"StudentName":"John","StudentCountryName":"US"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c98746a330fd0aa0d2fe4a8")
}
> db.NotAndDemo.insertOne({"StudentName":"John","StudentCountryName":"UK"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c987478330fd0aa0d2fe4a9")
}
> db.NotAndDemo.insertOne({"StudentName":"David","StudentCountryName":"AUS"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c987487330fd0aa0d2fe4aa")
}
> db.NotAndDemo.insertOne({"StudentName":"Chris","StudentCountryName":"UK"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c9874ac330fd0aa0d2fe4ab")
}
> db.NotAndDemo.insertOne({"StudentName":"Chris","StudentCountryName":"US"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c9874b7330fd0aa0d2fe4ac")
}

以下は、find()メソッドを使用してコレクションからすべてのドキュメントを表示するためのクエリです

> db.NotAndDemo.find().pretty();
This will produce the following output:
{
   "_id" : ObjectId("5c98746a330fd0aa0d2fe4a8"),
   "StudentName" : "John",
   "StudentCountryName" : "US"
}
{
   "_id" : ObjectId("5c987478330fd0aa0d2fe4a9"),
   "StudentName" : "John",
   "StudentCountryName" : "UK"
}
{
   "_id" : ObjectId("5c987487330fd0aa0d2fe4aa"),
   "StudentName" : "David",
   "StudentCountryName" : "AUS"
}
{
   "_id" : ObjectId("5c9874ac330fd0aa0d2fe4ab"),
   "StudentName" : "Chris",
   "StudentCountryName" : "UK"
}
{
   "_id" : ObjectId("5c9874b7330fd0aa0d2fe4ac"),
   "StudentName" : "Chris",
   "StudentCountryName" : "US"
}

以下は、NOTとANDを一緒に使用するためのクエリです。これはNOT(X AND Y)のNOTXまたはNOTYと同じです

> db.NotAndDemo.find({
...    "$or": [
...       {"StudentName": {"$ne": "Chris"}},
...       {"StudentCountryName": {"$ne": "US"}}
...    ]
... }).pretty();

これにより、次の出力が生成されます

{
   "_id" : ObjectId("5c98746a330fd0aa0d2fe4a8"),
   "StudentName" : "John",
   "StudentCountryName" : "US"
}
{
   "_id" : ObjectId("5c987478330fd0aa0d2fe4a9"),
   "StudentName" : "John",
   "StudentCountryName" : "UK"
}
{
   "_id" : ObjectId("5c987487330fd0aa0d2fe4aa"),
   "StudentName" : "David",
   "StudentCountryName" : "AUS"
}
{
   "_id" : ObjectId("5c9874ac330fd0aa0d2fe4ab"),
   "StudentName" : "Chris",
   "StudentCountryName" : "UK"
}

  1. ローカルホストとは何ですか?どのように使用できますか?

    ローカルホスト(「ループバックアドレス」とも呼ばれます)は、自分のコンピューターまたはマシンへのIP接続または呼び出しを確立するために使用されます。ループバックアドレスは通常、ネットワークのコンテキストで使用され、コンピューターにIPスタックを検証する機能を提供します。 ネットワーキングのバックグラウンドまたは関心を持っている人は誰でも、この分野に関連するコンピュータ用語を学び、理解することが重要であることがわかります。 Localhostは、コンピューター技術者にとって有益であると見なされているそのような用語の1つです。ローカルホストの重要性と使用法を理解することも、ネットワーキング用語へ

  2. Cortana と Alexa を一緒に使用する方法

    Microsoft は、1 月の Build 開発者会議で発表した後、ついに Windows 10 PC に Alexa を、Echo スピーカーに Cortana をもたらします。現在、プレビューは米国でのみ利用可能ですが、このパートナーシップには長い道のりがあるようです. 私たちは多面的な世界に住んでおり、デバイスにアシスタントを搭載することが理にかなっており、有益であることが証明されています.個々のオペレーティング システムではなく、アプリなどの 3 つのアシスタントにアクセスできることほど優れたものはありません。 現在、統合は基本的なものですが、間もなく Cortana と Ale