////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

=== Basic Querying
GORM for MongoDB supports all of the https://gorm.grails.org/latest/hibernate/manual/index.html#querying[regular methods] for executing GORM queries apart from HQL, which is a Hibernate specific query language more appropriate for SQL databases.

If you wish to execute a native MongoDB query you can use the `find` method that takes a https://api.mongodb.com/java/current/org/bson/conversions/Bson.html[Bson] argument. For example:

[source,groovy]
----
include::{sourcedir}/gorm/src/test/groovy/grails/gorm/tests/FindNativeSpec.groovy[tags=nativeImport]
...
include::{sourcedir}/gorm/src/test/groovy/grails/gorm/tests/FindNativeSpec.groovy[tags=nativeFind,indent=0]
----

The `find` method will return a https://api.mongodb.com/java/current/com/mongodb/client/FindIterable.html[FindIterable] instance that you can then use to further customize via https://api.mongodb.com/java/current/com/mongodb/client/model/Filters.html[filters], https://api.mongodb.com/java/current/com/mongodb/client/model/Sorts.html[sorting] and https://api.mongodb.com/java/current/com/mongodb/client/model/Projections.html[projections].

TIP: For the full MongoDB client model refer to the https://api.mongodb.com/java/current/com/mongodb/client/model/package-summary.html[com.mongodb.client.model] package.

The `find` method will return instances of your domain class for each query. If you wish to instead obtain MongoDB https://api.mongodb.com/java/current/org/bson/Document.html[Document] instance then you should use the `collection` property of the domain class:

[source,groovy]
----
include::{sourcedir}/gorm/src/test/groovy/grails/gorm/tests/FindNativeSpec.groovy[tags=nativeImport]
...
include::{sourcedir}/gorm/src/test/groovy/grails/gorm/tests/FindNativeSpec.groovy[tags=collectionFind,indent=0]
----
