You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created a sample app to try out MongoDB Mobile, but I cannot figure out how to query. There doesn't appear to be any documentation specific to Android in this regard (if there is, please share!). Currently, the following code will check "overview.name" for an exact match equal to "test". But I'd like to do a full-text search so that something like "this is a test name" or "Test name" would also match. Thanks for your help!
classMainActivity : AppCompatActivity() {
overridefunonCreate(savedInstanceState:Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val fileName ="sample.json"val sampleData = application.assets.open(fileName).bufferedReader().use{ it.readText() }
val doc =Document.parse(sampleData)
val rawObjects = doc.getValue("assets")
val documentsMap = rawObjects
?.asList<Map<String, Any?>>()
?.filter { it.isNotEmpty() }
?: java.util.ArrayList()
// Create the default Stitch Clientval client =Stitch.initializeDefaultAppClient("testmongodb-qopzy")
// Create a Client for MongoDB Mobile (initializing MongoDB Mobile)val mobileClient = client.getServiceClient(LocalMongoDbService.clientFactory)
// Point to the target collection and insert a documentval localCollection = mobileClient.getDatabase("my_db").getCollection("assets")
val startInsert =System.nanoTime()
localCollection.insertMany(documentsMap.map { Document(it) })
val endInsert =System.nanoTime()
//Find all documents that match the find criteriaval query =Document()
query.put("overview.name", BsonString("test"))
val startQuery =System.nanoTime()
val cursor = localCollection.find(query)
val results = cursor.into(ArrayList<Document>()) asArrayList<Document>
val endQuery =System.nanoTime()
Log.v("Results: ", results.toString())
Log.v("Insert duration: ", (startInsert - endInsert).toString())
Log.v("Query duration: ", (startQuery - endQuery).toString())
}
}
The text was updated successfully, but these errors were encountered:
I created a sample app to try out MongoDB Mobile, but I cannot figure out how to query. There doesn't appear to be any documentation specific to Android in this regard (if there is, please share!). Currently, the following code will check "overview.name" for an exact match equal to "test". But I'd like to do a full-text search so that something like "this is a test name" or "Test name" would also match. Thanks for your help!
The text was updated successfully, but these errors were encountered: