I’m new to CB, I create a DB and saved few doc’s in the default collection of the database using this function
fun addStudent(studentName: String) {
// Create a document
val stdDocument = MutableDocument()
.setString("type", "Student")
.setString("studentName", studentName)
// Save the document to the database
try {
database?.defaultCollection?.save(stdDocument)
println("Student saved")
} catch (e: CouchbaseLiteException) {
e.printStackTrace()
}
}
but while retreving the data by using this query:
fun getSavedStudents(): ResultSet? {
// Query for incomplete tasks
val query = database?.defaultCollection?.let {
QueryBuilder.select(SelectResult.all())
.from(DataSource.collection(it))
.where(
Expression.property("type").equalTo(Expression.string("Student"))
)
}
return try {
query?.execute()
} catch (e: CouchbaseLiteException) {
e.printStackTrace()
null
}
}
im geting ResultSet, but after iterating the result set I’m not able to get the result I need to convert the each result to a list() or map() or JSON and have to fetch using the key “studentName”
here is the printed result to json string:
—> {“_default”:{“studentName”:“Praneeth”,“type”:“Student”}}
—> {“_default”:{“studentName”:“Praneeth”,“type”:“Student”}}
—> {“_default”:{“studentName”:“Praneeth”,“type”:“Student”}}
—> {“_default”:{“studentName”:“john”,“type”:“Student”}}
—> {“_default”:{“studentName”:“test”,“type”:“Student”}}
—> {“_default”:{“studentName”:“gani”,“type”:“Student”}}
why is this “_default” key is getting created