빈 데이터를 처리하기 위해 $ne 연산자를 사용할 수 있습니다. 문서로 컬렉션을 만들어 봅시다. 다음은 쿼리입니다.
>db.handlingAndEmptyDataDemo.insertOne({"StudentName":"John","StudentCountryName":""});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9cbd5ca629b87623db1b12")
}
>db.handlingAndEmptyDataDemo.insertOne({"StudentName":"John","StudentCountryName":null});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9cbd6ba629b87623db1b13")
}
> db.handlingAndEmptyDataDemo.insertOne({"StudentName":"John"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9cbd71a629b87623db1b14")
} 다음은 find() 메서드를 사용하여 컬렉션의 모든 문서를 표시하는 쿼리입니다.
> db.handlingAndEmptyDataDemo.find().pretty();
그러면 다음과 같은 출력이 생성됩니다.
{
"_id" : ObjectId("5c9cbd5ca629b87623db1b12"),
"StudentName" : "John",
"StudentCountryName" : ""
}
{
"_id" : ObjectId("5c9cbd6ba629b87623db1b13"),
"StudentName" : "John",
"StudentCountryName" : null
}
{ "_id" : ObjectId("5c9cbd71a629b87623db1b14"), "StudentName" : "John" } 다음은 $ne
을 사용하여 빈 데이터를 처리하는 쿼리입니다.> db.handlingAndEmptyDataDemo.find({StudentCountryName: {$ne: null}}); 그러면 다음과 같은 출력이 생성됩니다.
{ "_id" : ObjectId("5c9cbd5ca629b87623db1b12"), "StudentName" : "John", "StudentCountryName" : "" }