Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory efficient ExportCollection() #130

Open
ostafen opened this issue Jun 19, 2023 · 1 comment · May be fixed by #131
Open

Memory efficient ExportCollection() #130

ostafen opened this issue Jun 19, 2023 · 1 comment · May be fixed by #131
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ostafen
Copy link
Owner

ostafen commented Jun 19, 2023

At the current state, ExportCollection() loads all documents in memory before exporting them to a json file.

	result, err := db.FindAll(query.NewQuery(collectionName))
	if err != nil {
		return err
	}

	docs := make([]map[string]interface{}, 0)
	for _, doc := range result {
		docs = append(docs, doc.AsMap())
	}

	jsonString, err := json.Marshal(docs)
	if err != nil {
		return err
	}

This is far from being optimized, since collections could contain thousands or millions of documents.
Export should thus performed gradually by writing documents to the output file one by one (the ForEach() method can be used to iterate no documents).

@ostafen ostafen added enhancement New feature or request good first issue Good for newcomers labels Jun 19, 2023
@ostafen ostafen linked a pull request Jun 21, 2023 that will close this issue
@ShivamKumar2002
Copy link

Is someone working on this or is it still available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants