Ishes with /n in string

in Mongosh i see

 description: '1\n2\n3\n\n\n5',

when i use motor

from motor.motor_asyncio import AsyncIOMotorClient
client = AsyncIOMotorClient(MONGO_URL)
marks = await Dots.marks.find(marks_query).to_list(length=None)
print("--------------------------------")
print(repr(marks))
print("--------------------------------")

in consoi i get

--------------------------------
[{'_id': ObjectId('684d6f1db27d0f18e6a76e5e'), 'description': '1235', ...
--------------------------------

ist loose lose all /n

Python 3.10.12

Don’t use “\n” … use Python’s builtin os.linesep

How/where?
I get my text from the frontend with \n, then I need to save it and later send it back to the frontend.

I end up writing my own “serializer” that replaces \n with some symbol,
and when sending it back to the frontend, I replace it back.

right, when you replace it, replace with

import os
os.linesep
1 Like

Ok, your solution also works, but where in the documentation does it say that \n will be replaced with “”?
I consider this clearly unexpected behavior — it should be either patched or documented

You may be right about unexpected behavior. File an issue.

I cannot reproduce, perhaps a local environment issue. Also Motor is now deprecated and End of Life next year.

As of May 14, 2025, Motor is deprecated in favor of the GA release of the PyMongo Async API in the PyMongo library. We will not add new features to Motor, and we will provide only bug fixes until it reaches end of life on May 14, 2026. After that, we will fix only critical bugs until final support ends on May 14, 2027. We strongly recommend migrating to the PyMongo Async API while Motor is still supported.

For more information about migrating, see the Migrate to PyMongo Async guide in the PyMongo documentation.

# app
import asyncio
import os
from motor.motor_asyncio import AsyncIOMotorClient

async def runit():
  uri = os.getenv('MONGODB_URI','mongodb://localhost')

  client = AsyncIOMotorClient(uri)

  try:
      resp = await client.test.foo.find().to_list(length=500)
      print(resp)
  except Exception as e:
      print(e)
      
asyncio.run(runit())
python --version; pip freeze; python app
Python 3.10.12
dnspython==2.7.0
motor==3.7.1
pymongo==4.13.2
[{'_id': ObjectId('6852d024edb282dc1cc59f35'), 'x': 'a\nb\nc\n'}]

Okay, I’m trying to perform a transaction using PyMongo Async, but I can’t get it to work because there’s no documentation about GridFS. Currently, I’m using AsyncIOMotorGridFSBucket.

Then somehow I found that there’s also from gridfs.asynchronous import AsyncGridFSBucket.

But overall, this is a terrible experience migrating to async.