我正在与 Django 和 MongoDb 一起使用 Django。如何返回包含行号的查询集?我曾尝试探索 mongo 的聚合功能,但无法达到结果。
import uuid
from django import models
class Snippet(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False,
)
title = models.CharField(
max_length=100,
)
body = models.TextField()
预期产出
{
"id": "a3cee4c9-6e23-4710-81e2-dda67a2b98d5",
"title": "sad",
"body": "a sad story",
"row" : "1"
},
{
"id": "3e8b054e-aea7-4fa0-9019-3afa1a1efd15",
"title": "happy",
"body": "a happy story",
"row" : "2"
},
{
"id": "7e8d782e-583f-4f31-96e6-8dc267e69e9f",
"title": "angry",
"body": "an angry man",
"row" : "3"
}