0

I have two schemas as below

Schema1

{ 
   "_id": ObjectId,
   "isSet": Boolean,
}

Schema2

{
    "_id":ObjectId,
    "name": "String",
    "schema1Id": {type: ObjectId, "ref": "Schema1"}
  }

Now I want to query schema2 for all documents with name and isSet with value false.

How can I do this using mongo. I don't want to use $lookup as it doesn't support in sharding.

If I keep isSet in Schema2 as well, I need to update both schemas when I update the value of isSet, as it will be costly operation, I don't want to do that.

Is there a better solution to achieve this?

  • The "ways to achieve" are already long discussed considering MongoDB has been around for some time, and quite some time before `$lookup`. There is no "join on the server" possible without the `$lookup` operator. Everything else requires pulling data from collections an assembling manually. And every existing method for many years has already been documented. Choose one, or realize that maybe your design pattern probably does not need a join and you should instead embed or otherwise refactor your thinking here. – Neil Lunn Jun 07 '18 at 07:07
  • Then what if I use lookup and want to shard – Kodanda Rama Durgarao Poluri Jun 07 '18 at 07:14
  • I just said there are other options. But none of them are a "join". It's not supported. There's a good reason why it's not supported. Not an RDBMS. – Neil Lunn Jun 07 '18 at 07:16

0 Answers0