Hi @Prakhar_Khanna and welcome in the MongoDB Community
!
There is no such limitation on M0 Free Tier in Atlas.
Here is a piece of code that proves it:
package com.mongodb.quickstart;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.json.JsonWriterSettings;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import static com.mongodb.client.model.Aggregates.lookup;
import static com.mongodb.client.model.Aggregates.match;
import static com.mongodb.client.model.Filters.eq;
import static java.util.Arrays.asList;
public class AggregationFrameworkCommunity {
public static void main(String[] args) {
String connectionString = System.getProperty("mongodb.uri");
try (MongoClient mongoClient = MongoClients.create(connectionString)) {
MongoCollection<Document> persons = mongoClient.getDatabase("test").getCollection("persons");
System.out.println("Dropping collection 'test.persons'");
persons.drop();
System.out.println("Insert 2 sample docs...");
insertSampleDocs(persons);
aggregationWithLookup(persons);
}
}
private static void insertSampleDocs(MongoCollection<Document> persons) {
List<Integer> maxFriends = Collections.singletonList(2);
Document maxime = new Document("_id", 1).append("name", "Maxime").append("friends", maxFriends);
Document prakhar = new Document("_id", 2).append("name", "Prakhar");
persons.insertMany(asList(maxime, prakhar));
}
private static void aggregationWithLookup(MongoCollection<Document> persons) {
Bson match = match(eq("name", "Maxime"));
Bson lookup = lookup("persons", "friends", "_id", "friends");
List<Document> results = persons.aggregate(asList(match, lookup)).into(new ArrayList<>());
System.out.println("==> Print result of Lookup");
results.forEach(printDocuments());
}
private static Consumer<Document> printDocuments() {
return doc -> System.out.println(doc.toJson(JsonWriterSettings.builder().indent(true).build()));
}
}
Result in my test.persons
collection:
Atlas Free-shard-0 [primary] test> db.persons.find()
[
{ _id: 1, name: 'Maxime', friends: [ 2 ] },
{ _id: 2, name: 'Prakhar' }
]
Java program output:
Dropping collection 'test.persons'
Insert 2 sample docs...
==> Print result of Lookup
{
"_id": 1,
"name": "Maxime",
"friends": [
{
"_id": 2,
"name": "Prakhar"
}
]
}
Everything seem to work as intended for me.
Cheers,
Maxime.