MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / QueryAllDocs

Method QueryAllDocs

db/query.go:705–739  ·  view source on GitHub ↗

AllDocs returns all non-deleted documents in the bucket between startKey and endKey

(ctx context.Context, startKey string, endKey string)

Source from the content-addressed store, hash-verified

703
704// AllDocs returns all non-deleted documents in the bucket between startKey and endKey
705func (c *DatabaseCollection) QueryAllDocs(ctx context.Context, startKey string, endKey string) (sgbucket.QueryResultIterator, error) {
706
707 // View Query
708 if c.useViews() {
709 opts := Body{"stale": false, "reduce": false}
710 if startKey != "" {
711 opts[QueryParamStartKey] = startKey
712 }
713 if endKey != "" {
714 opts[QueryParamEndKey] = endKey
715 }
716 return c.dbCtx.ViewQueryWithStats(ctx, c.dataStore, DesignDocSyncHousekeeping(), ViewAllDocs, opts)
717 }
718
719 // N1QL Query
720 allDocsQueryStatement := replaceSyncTokensQuery(QueryAllDocs.statement, c.UseXattrs())
721 allDocsQueryStatement = replaceIndexTokensQuery(allDocsQueryStatement, sgIndexes[IndexAllDocs], c.UseXattrs(), c.numIndexPartitions())
722
723 params := make(map[string]interface{}, 0)
724 if startKey != "" {
725 allDocsQueryStatement = fmt.Sprintf("%s AND META(%s).id >= $startkey",
726 allDocsQueryStatement, base.KeyspaceQueryAlias)
727 params[QueryParamStartKey] = startKey
728 }
729 if endKey != "" {
730 allDocsQueryStatement = fmt.Sprintf("%s AND META(%s).id <= $endkey",
731 allDocsQueryStatement, base.KeyspaceQueryAlias)
732 params[QueryParamEndKey] = endKey
733 }
734
735 allDocsQueryStatement = fmt.Sprintf("%s ORDER BY META(%s).id",
736 allDocsQueryStatement, base.KeyspaceQueryAlias)
737
738 return N1QLQueryWithStats(ctx, c.dataStore, QueryTypeAllDocs, allDocsQueryStatement, params, base.RequestPlus, QueryAllDocs.adhoc, c.dbStats(), c.slowQueryWarningThreshold())
739}
740
741func (c *DatabaseCollection) QueryTombstones(ctx context.Context, olderThan time.Time, limit int) (sgbucket.QueryResultIterator, error) {
742

Callers 2

ForEachDocIDMethod · 0.95
TestAllDocsQueryFunction · 0.80

Calls 10

useViewsMethod · 0.95
UseXattrsMethod · 0.95
numIndexPartitionsMethod · 0.95
dbStatsMethod · 0.95
replaceSyncTokensQueryFunction · 0.85
replaceIndexTokensQueryFunction · 0.85
N1QLQueryWithStatsFunction · 0.85
ViewQueryWithStatsMethod · 0.80

Tested by 1

TestAllDocsQueryFunction · 0.64