Save object and Querying them with N1qlQuery just after insertion?


#1

Hello,
Sorry i’m an old developer (Many years on Relational MySQL!!!) so excuse if my question is a non-sense…

I don’t understand why the following code doesn’t work :slightly_smiling_face:

for(int i=0;i<10;i++)
{
BUCKET.insert(RawJsonDocument.create(“Objet::”+i),PersistTO.NONE);
// For me, as i don’t PersistTO.MASTER, the object will be perhaps on memory…_
}

N1qlQuery query = N1qlQuery.simple(“select * from BUCKET_NAME”);
System.out.println(BUCKET.query(query).allRows().size()); // => It print 0!!!
// I’m excepting 10 rows, as the object exists on memory

Thread.sleep(500); // Just wait a little!
query = N1qlQuery.simple(“select * from BUCKET_NAME”);
System.out.println(BUCKET.query(query).allRows().size()); // => Ok now it prints 10!

What i misunderstand???

Thanks!


#2

The indexes are a bit behind the data nodes since indexes are maintained asynchronously (eventually). You can provide scan_consistency as part of query.


#3

Yeees! Thanks a lot!


#4

Matthew Groves blogged about scan consistency. There’s a video too.